Skip to content

Commit be3aede

Browse files
authored
Release/0.6.6 (#60)
* #58 -AS clause always injected in generated SQL * Code review: optional true for AsKeyword * Code review:minor change * Bugfix: bug fixes with introduction of AsKeyword boolean on statement parts * Code review: minor change * Code review: minor change
1 parent d95fb53 commit be3aede

19 files changed

+195
-148
lines changed

src/SqlParser.Tests/CoverageTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public void Top_Renders_Sql()
6363
{
6464
//ar top = new Top(new Expression.LiteralValue(new Value.Number("1")), false, false);
6565
var top = new Top(new TopQuantity.TopExpression(new Expression.LiteralValue(new Value.Number("1"))), false, false);
66+
6667
Assert.Equal("TOP (1)", top.ToSql());
6768
}
6869

src/SqlParser.Tests/Dialects/BigQueryDialectTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void Parse_Join_Constraint_Unnest_Alias()
195195
{
196196
new (new TableFactor.UnNest([new CompoundIdentifier(new Ident[] { "t1", "a" })])
197197
{
198-
Alias = new TableAlias("f"),
198+
Alias = new TableAlias("f", true),
199199
},
200200
new JoinOperator.Inner(new JoinConstraint.On(
201201
new BinaryOp(
@@ -442,12 +442,12 @@ public void Parse_Typeless_Struct_Syntax()
442442
Assert.Equal(expected, select.Projection.Skip(2).First().AsExpr());
443443

444444
expected = new Struct([
445-
new Named(new LiteralValue(new Value.Number("1")), "a"),
446-
new Named(new LiteralValue(new Value.SingleQuotedString("abc")), "b")
445+
new Named(new LiteralValue(new Value.Number("1")), "a", true),
446+
new Named(new LiteralValue(new Value.SingleQuotedString("abc")), "b", true)
447447
], []);
448448
Assert.Equal(expected, select.Projection.Skip(3).First().AsExpr());
449449

450-
expected = new Struct([new Named(new Identifier("str_col"), "abc")], []);
450+
expected = new Struct([new Named(new Identifier("str_col"), "abc", true)], []);
451451
Assert.Equal(expected, select.Projection.Skip(4).First().AsExpr());
452452
}
453453

@@ -769,7 +769,7 @@ CREATE VIEW myproject.mydataset.newview
769769
var create = VerifiedStatement<Statement.CreateView>(sql);
770770
var columns = new Sequence<ViewColumnDef>
771771
{
772-
new("name"),
772+
new("name"),
773773
new("age", Options: [new ColumnOption.Options([new SqlOption.KeyValue("description", new LiteralValue(new Value.DoubleQuotedString("field age")))])])
774774
};
775775
Assert.Equal(new ObjectName(["myproject", "mydataset", "newview"]), create.Name);

src/SqlParser.Tests/Dialects/HiveDialectTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void Parse_Create_Function()
244244
[Fact]
245245
public void Filter_As_Alias()
246246
{
247-
OneStatementParsesTo("SELECT name filter FROM region", "SELECT name AS filter FROM region");
247+
OneStatementParsesTo("SELECT name filter FROM region", "SELECT name filter FROM region");
248248
}
249249

250250
[Fact]

src/SqlParser.Tests/Dialects/MsSqlDialectTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public void Parse_MsSql_Single_Quoted_Identifiers()
3030
{
3131
DefaultDialects = [new MsSqlDialect(), new GenericDialect()];
3232

33-
OneStatementParsesTo("SELECT foo 'alias'", "SELECT foo AS 'alias'");
33+
OneStatementParsesTo("SELECT foo 'alias'", "SELECT foo 'alias'");
3434
}
3535

3636
[Fact]
3737
public void Parse_MsSql_Delimited_Identifiers()
3838
{
3939
OneStatementParsesTo(
4040
"SELECT [a.b!] [FROM] FROM foo [WHERE]",
41-
"SELECT [a.b!] AS [FROM] FROM foo AS [WHERE]");
41+
"SELECT [a.b!] [FROM] FROM foo [WHERE]");
4242
}
4343

4444
[Fact]

src/SqlParser.Tests/Dialects/MySqlDialectTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,14 @@ public void Parse_Update_With_Joins()
496496

497497
var table = new TableWithJoins(new TableFactor.Table("orders")
498498
{
499-
Alias = new TableAlias("o")
499+
Alias = new TableAlias("o", true)
500500
})
501501
{
502502
Joins = new Join[]
503503
{
504504
new(new TableFactor.Table("customers")
505505
{
506-
Alias = new TableAlias("c")
506+
Alias = new TableAlias("c", true)
507507
})
508508
{
509509
JoinOperator = new JoinOperator.Inner(new JoinConstraint.On(new BinaryOp(
@@ -1090,7 +1090,7 @@ public void Parse_Json_Table()
10901090
new JsonTableColumnErrorHandling.Null()))
10911091
])
10921092
{
1093-
Alias = new TableAlias("t")
1093+
Alias = new TableAlias("t", true)
10941094
};
10951095

10961096
Assert.Equal(expected, joinTable.From![0].Relation);
@@ -1114,7 +1114,7 @@ public void Parse_Create_Table_With_Column_Collate()
11141114
[Fact]
11151115
public void Parse_Lock_Tables()
11161116
{
1117-
OneStatementParsesTo("LOCK TABLES trans t READ, customer WRITE", "LOCK TABLES trans AS t READ, customer WRITE");
1117+
OneStatementParsesTo("LOCK TABLES trans t READ, customer WRITE", "LOCK TABLES trans t READ, customer WRITE");
11181118

11191119
//VerifiedStatement("LOCK TABLES trans AS t READ, customer WRITE");
11201120
//VerifiedStatement("LOCK TABLES trans AS t READ LOCAL, customer WRITE");

src/SqlParser.Tests/Dialects/PostgresDialectTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ public void Parse_Pg_Returning()
10861086

10871087
var expected = new SelectItem[]
10881088
{
1089-
new SelectItem.ExpressionWithAlias(new Identifier("temp_lo"), "lo"),
1090-
new SelectItem.ExpressionWithAlias(new Identifier("temp_hi"), "hi"),
1089+
new SelectItem.ExpressionWithAlias(new Identifier("temp_lo"), "lo", true),
1090+
new SelectItem.ExpressionWithAlias(new Identifier("temp_hi"), "hi", true),
10911091
new SelectItem.UnnamedExpression(new Identifier("prcp"))
10921092
};
10931093

@@ -1792,7 +1792,7 @@ public void Parse_Delimited_Identifiers()
17921792

17931793
var table = new TableFactor.Table(new ObjectName(new Ident("a table", Symbols.DoubleQuote)))
17941794
{
1795-
Alias = new TableAlias(new Ident("alias", Symbols.DoubleQuote))
1795+
Alias = new TableAlias(new Ident("alias", Symbols.DoubleQuote), true)
17961796
};
17971797

17981798
Assert.Equal(table, select.From!.Single().Relation);
@@ -1809,7 +1809,7 @@ public void Parse_Delimited_Identifiers()
18091809

18101810
Assert.Equal(new SelectItem.ExpressionWithAlias(new Identifier(
18111811
new Ident("simple id", Symbols.DoubleQuote)),
1812-
new Ident("column alias", Symbols.DoubleQuote)),
1812+
new Ident("column alias", Symbols.DoubleQuote), true),
18131813
select.Projection[2]);
18141814

18151815
VerifiedStatement("CREATE TABLE \"foo\" (\"bar\" \"int\")");
@@ -1921,7 +1921,7 @@ public void Parse_Dollar_Quoted_String()
19211921
Assert.Equal(new LiteralValue(new Value.DollarQuotedString(new DollarQuotedStringValue("hello"))), projection[0].AsExpr());
19221922
Assert.Equal(new LiteralValue(new Value.DollarQuotedString(new DollarQuotedStringValue("world", "tag_name"))), projection[1].AsExpr());
19231923
Assert.Equal(new LiteralValue(new Value.DollarQuotedString(new DollarQuotedStringValue("Foo$Bar"))), projection[2].AsExpr());
1924-
var expr = new SelectItem.ExpressionWithAlias(new LiteralValue(new Value.DollarQuotedString(new DollarQuotedStringValue("Foo$Bar"))), "col_name");
1924+
var expr = new SelectItem.ExpressionWithAlias(new LiteralValue(new Value.DollarQuotedString(new DollarQuotedStringValue("Foo$Bar"))), "col_name", false);
19251925
Assert.Equal(expr, projection[3]);
19261926
Assert.Equal(new LiteralValue(new Value.DollarQuotedString(new DollarQuotedStringValue(""))), projection[4].AsExpr());
19271927
Assert.Equal(new LiteralValue(new Value.DollarQuotedString(new DollarQuotedStringValue("", "tag_name"))), projection[5].AsExpr());
@@ -2085,7 +2085,7 @@ public void Parse_Join_Constraint_Unnest_Alias()
20852085
{
20862086
new (new TableFactor.UnNest([new CompoundIdentifier(new Ident[] { "t1", "a" })])
20872087
{
2088-
Alias = new TableAlias("f"),
2088+
Alias = new TableAlias("f", true),
20892089
},
20902090
new JoinOperator.Inner(new JoinConstraint.On(
20912091
new BinaryOp(

src/SqlParser.Tests/Dialects/RedshiftDialectTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void Parse_Delimited_Identifiers()
5656

5757
var table = new TableFactor.Table(new ObjectName(new Ident("a table", Symbols.DoubleQuote)))
5858
{
59-
Alias = new TableAlias(new Ident("alias", Symbols.DoubleQuote))
59+
Alias = new TableAlias(new Ident("alias", Symbols.DoubleQuote), true)
6060
};
6161

6262
Assert.Equal(table, select.From!.Single().Relation);

src/SqlParser.Tests/Dialects/SnowflakeDialectTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,25 @@ public void Test_Single_Table_In_Parenthesis_With_Alias()
104104

105105
OneStatementParsesTo(
106106
"SELECT * FROM (a NATURAL JOIN (b) c )",
107-
"SELECT * FROM (a NATURAL JOIN b AS c)");
107+
"SELECT * FROM (a NATURAL JOIN b c)");
108108
OneStatementParsesTo(
109109
"SELECT * FROM (a NATURAL JOIN ((b)) c )",
110-
"SELECT * FROM (a NATURAL JOIN b AS c)");
110+
"SELECT * FROM (a NATURAL JOIN b c)");
111111
OneStatementParsesTo(
112112
"SELECT * FROM (a NATURAL JOIN ( (b) c ) )",
113-
"SELECT * FROM (a NATURAL JOIN b AS c)");
113+
"SELECT * FROM (a NATURAL JOIN b c)");
114114
OneStatementParsesTo(
115115
"SELECT * FROM (a NATURAL JOIN ( (b) as c ) )",
116116
"SELECT * FROM (a NATURAL JOIN b AS c)");
117117
OneStatementParsesTo(
118118
"SELECT * FROM (a alias1 NATURAL JOIN ( (b) c ) )",
119-
"SELECT * FROM (a AS alias1 NATURAL JOIN b AS c)");
119+
"SELECT * FROM (a alias1 NATURAL JOIN b c)");
120120
OneStatementParsesTo(
121121
"SELECT * FROM (a as alias1 NATURAL JOIN ( (b) as c ) )",
122122
"SELECT * FROM (a AS alias1 NATURAL JOIN b AS c)");
123123
OneStatementParsesTo(
124124
"SELECT * FROM (a NATURAL JOIN b) c",
125-
"SELECT * FROM (a NATURAL JOIN b) AS c");
125+
"SELECT * FROM (a NATURAL JOIN b) c");
126126

127127
DefaultDialects = [new SnowflakeDialect()];
128128
var ex = Assert.Throws<ParserException>(() => ParseSqlStatements("SELECT * FROM (a b) c"));
@@ -259,7 +259,7 @@ public void Parse_Delimited_Identifiers()
259259

260260
var table = new TableFactor.Table(new ObjectName(new Ident("a table", Symbols.DoubleQuote)))
261261
{
262-
Alias = new TableAlias(new Ident("alias", Symbols.DoubleQuote))
262+
Alias = new TableAlias(new Ident("alias", Symbols.DoubleQuote), true)
263263
};
264264

265265
Assert.Equal(table, select.From!.Single().Relation);
@@ -1083,14 +1083,14 @@ ASOF JOIN quotes_unixtime AS qu
10831083

10841084
var expected = new TableWithJoins(new TableFactor.Table("trades_unixtime")
10851085
{
1086-
Alias = new TableAlias("tu")
1086+
Alias = new TableAlias("tu", true)
10871087
})
10881088
{
10891089
Joins =
10901090
[
10911091
new Join(new TableFactor.Table("quotes_unixtime")
10921092
{
1093-
Alias = new TableAlias("qu")
1093+
Alias = new TableAlias("qu", true)
10941094
},
10951095
new JoinOperator.AsOf(new BinaryOp(
10961096
new CompoundIdentifier(["tu", "trade_time"]),

0 commit comments

Comments
 (0)