diff --git a/src/Carbunql/Analysis/Parser/TableParser.cs b/src/Carbunql/Analysis/Parser/TableParser.cs index fe873bbd..9ac1e5d0 100644 --- a/src/Carbunql/Analysis/Parser/TableParser.cs +++ b/src/Carbunql/Analysis/Parser/TableParser.cs @@ -28,10 +28,18 @@ public static TableBase Parse(ITokenReader r) if (r.Peek().IsEqualNoCase(".")) { - //schema.table - var schema = item; - r.Read("."); - return new PhysicalTable(schema, r.Read()); + var value = item; + while (r.Peek() == ".") + { + r.Read("."); + value += "." + r.Read(); + }; + + var parts = value.Split("."); + var table = parts[parts.Length - 1]; + var schema = value.Substring(0, value.Length - table.Length - 1); + + return new PhysicalTable(schema, table); } if (r.Peek().IsEqualNoCase("(")) diff --git a/src/Carbunql/Analysis/Parser/ValueParser.cs b/src/Carbunql/Analysis/Parser/ValueParser.cs index 84981179..8cb43e9d 100644 --- a/src/Carbunql/Analysis/Parser/ValueParser.cs +++ b/src/Carbunql/Analysis/Parser/ValueParser.cs @@ -151,10 +151,18 @@ internal static ValueBase ParseCore(ITokenReader r) if (r.Peek() == ".") { - //table.column - var table = item; - r.Read("."); - return new ColumnValue(table, r.Read()); + var value = item; + while (r.Peek() == ".") + { + r.Read("."); + value += "." + r.Read(); + }; + + var parts = value.Split("."); + var column = parts[parts.Length - 1]; + var table = value.Substring(0, value.Length - column.Length - 1); + + return new ColumnValue(table, column); } //omit table column diff --git a/src/Carbunql/Extensions/intExtension.cs b/src/Carbunql/Extensions/intExtension.cs index 1df21da8..ecee87c7 100644 --- a/src/Carbunql/Extensions/intExtension.cs +++ b/src/Carbunql/Extensions/intExtension.cs @@ -1,5 +1,4 @@ using Cysharp.Text; -using System.Text; namespace Carbunql.Extensions; diff --git a/test/Carbunql.Analysis.Test/TableParserTest.cs b/test/Carbunql.Analysis.Test/TableParserTest.cs index ebe512d4..1f3964ee 100644 --- a/test/Carbunql.Analysis.Test/TableParserTest.cs +++ b/test/Carbunql.Analysis.Test/TableParserTest.cs @@ -23,6 +23,20 @@ public void PhysicalTable() Assert.Equal(3, lst.Count); } + [Fact] + public void CatalogSchemaTable() + { + var text = @"catalog.schema.table"; + + var v = ValueParser.Parse(text); + Monitor.Log(v); + + var lst = v.GetTokens().ToList(); + Assert.Equal(3, lst.Count); + + Assert.Equal(text, v.ToText()); + } + [Fact] public void PhysicalTable2() { diff --git a/test/Carbunql.Analysis.Test/ValueParseTest.cs b/test/Carbunql.Analysis.Test/ValueParseTest.cs index 6ea145b6..e12eb6f0 100644 --- a/test/Carbunql.Analysis.Test/ValueParseTest.cs +++ b/test/Carbunql.Analysis.Test/ValueParseTest.cs @@ -739,4 +739,18 @@ public void PrefixOfStringLiterals() Assert.Equal(expect, v.ToText()); } + + [Fact] + public void CatalogSchemaTableColumn() + { + var text = @"catalog.schema.table.column"; + + var v = ValueParser.Parse(text); + Monitor.Log(v); + + var lst = v.GetTokens().ToList(); + Assert.Equal(3, lst.Count); + + Assert.Equal(text, v.ToText()); + } } \ No newline at end of file