File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed
java/net/sf/jsqlparser/expression
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/expression Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ public void setAliasColumns(List<AliasColumn> aliasColumns) {
65
65
66
66
@ Override
67
67
public String toString () {
68
- String alias = (useAs ? " AS " : " " ) + name ;
68
+ String alias = (useAs ? " AS " : " " ) + ( name != null ? name : "" ) ;
69
69
70
70
if (aliasColumns != null && !aliasColumns .isEmpty ()) {
71
71
StringBuilder ac = new StringBuilder ();
@@ -75,10 +75,10 @@ public String toString() {
75
75
}
76
76
ac .append (col .name );
77
77
if (col .colDataType != null ) {
78
- ac .append (" " ).append (col .colDataType . toString () );
78
+ ac .append (" " ).append (col .colDataType );
79
79
}
80
80
}
81
- alias += "(" + ac + ")" ;
81
+ alias += name != null ? "(" + ac + ")" : ac ;
82
82
}
83
83
84
84
return alias ;
@@ -99,6 +99,16 @@ public Alias withAliasColumns(List<AliasColumn> aliasColumns) {
99
99
return this ;
100
100
}
101
101
102
+
103
+ public Alias addAliasColumns (String ... columnNames ) {
104
+ List <AliasColumn > collection =
105
+ Optional .ofNullable (getAliasColumns ()).orElseGet (ArrayList ::new );
106
+ for (String columnName : columnNames ) {
107
+ collection .add (new AliasColumn (columnName ));
108
+ }
109
+ return this .withAliasColumns (collection );
110
+ }
111
+
102
112
public Alias addAliasColumns (AliasColumn ... aliasColumns ) {
103
113
List <AliasColumn > collection =
104
114
Optional .ofNullable (getAliasColumns ()).orElseGet (ArrayList ::new );
Original file line number Diff line number Diff line change @@ -2314,9 +2314,15 @@ LateralView LateralView() #LateralView:
2314
2314
tableAlias = new Alias(tableName, false);
2315
2315
}
2316
2316
]
2317
- <K_AS> columnName = RelObjectNameWithoutStart()
2317
+ <K_AS> columnName = RelObjectNameWithoutStart() { columnAlias = new Alias(columnName, true); }
2318
+
2319
+ // Spark SQL supports multiple Alias Columns: https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-lateral-view.html
2320
+ // we simulate this by setting the alias name to null and then just adding the columns
2321
+ [
2322
+ LOOKAHEAD(2) "," { columnAlias.setName(null); columnAlias.addAliasColumns( columnName); }
2323
+ columnName = RelObjectNameWithoutStart() { columnAlias.addAliasColumns( columnName); }
2324
+ ]
2318
2325
{
2319
- columnAlias = new Alias(columnName, true);
2320
2326
return new LateralView(
2321
2327
useOuter
2322
2328
, generatorFunction
Original file line number Diff line number Diff line change @@ -20,4 +20,12 @@ void testUDTF() throws JSQLParserException {
20
20
String sqlStr = "select udtf_1(words) as (a1, a2) from tab" ;
21
21
TestUtils .assertSqlCanBeParsedAndDeparsed (sqlStr , true );
22
22
}
23
+
24
+ @ Test
25
+ void testLateralViewMultipleColumns () throws JSQLParserException {
26
+ String sqlStr = "SELECT k, v \n " +
27
+ "FROM table \n " +
28
+ "LATERAL VIEW EXPLODE(a) exploded_data AS k, v;" ;
29
+ TestUtils .assertSqlCanBeParsedAndDeparsed (sqlStr , true );
30
+ }
23
31
}
You can’t perform that action at this time.
0 commit comments