Skip to content

Commit

Permalink
Merge pull request #368 from mk3008/351-parsing-does-not-work-when-sp…
Browse files Browse the repository at this point in the history
…ecifying-a-schema

Supports parsing when specifying catalogs and schemas
  • Loading branch information
mk3008 authored Mar 26, 2024
2 parents b45cd51 + 057bc1d commit 6dbaccb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
16 changes: 12 additions & 4 deletions src/Carbunql/Analysis/Parser/TableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("("))
Expand Down
16 changes: 12 additions & 4 deletions src/Carbunql/Analysis/Parser/ValueParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Carbunql/Extensions/intExtension.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Cysharp.Text;
using System.Text;

namespace Carbunql.Extensions;

Expand Down
14 changes: 14 additions & 0 deletions test/Carbunql.Analysis.Test/TableParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
14 changes: 14 additions & 0 deletions test/Carbunql.Analysis.Test/ValueParseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 6dbaccb

Please sign in to comment.