Skip to content

Commit ae635be

Browse files
committed
Generalized grammar to allow for function names inside of index DDL, not
just Z_ORDER_LAT_LON. IndexColumnList.FunctionType and tests have been modified to use GEO_LAT_LON instead of Z_ORDER_LAT_LON. Bumped version number to 1.6.1.
1 parent 00b0d1d commit ae635be

25 files changed

+171
-123
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<groupId>com.foundationdb</groupId>
1515
<artifactId>fdb-sql-parser</artifactId>
16-
<version>1.6.0-SNAPSHOT</version>
16+
<version>1.6.1-SNAPSHOT</version>
1717
<packaging>jar</packaging>
1818

1919
<name>FoundationDB SQL Parser</name>

src/main/java/com/foundationdb/sql/parser/IndexColumnList.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class IndexColumnList extends QueryTreeNodeList<IndexColumn>
2828

2929
public static enum FunctionType
3030
{
31-
Z_ORDER_LAT_LON, FULL_TEXT
31+
GEO_LAT_LON, FULL_TEXT
3232
// ADD MORE AS NEEDED
3333
}
3434

@@ -100,4 +100,10 @@ public String toString()
100100
functionApplication.functionType, functionApplication.firstArgumentPosition, functionApplication.lastArgumentPosition)
101101
: super.toString();
102102
}
103+
104+
public static FunctionType functionType(String functionName)
105+
{
106+
return Enum.valueOf(FunctionType.class, functionName.trim().toUpperCase());
107+
}
108+
103109
}

src/main/javacc/SQLGrammar.jj

Lines changed: 141 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,7 +2257,6 @@ TOKEN [IGNORE_CASE] :
22572257
| <XMLPARSE: "xmlparse">
22582258
| <XMLQUERY: "xmlquery">
22592259
| <XMLSERIALIZE: "xmlserialize">
2260-
| <Z_ORDER_LAT_LON: "z_order_lat_lon">
22612260
}
22622261

22632262
/* This list should contain non-SQL92 keywords that are not reserved.
@@ -8445,58 +8444,59 @@ indexItemList(IndexColumnList columnList) throws StandardException :
84458444

84468445
void indexItem(IndexColumnList columnList) throws StandardException :
84478446
{
8448-
String columnName;
8447+
String firstName = null;
8448+
String columnName = null;
84498449
boolean asc = true;
8450-
int spatialColumnCount;
8450+
int firstSpatialColumnPosition = -1;
8451+
int spatialColumnCount = -1;
84518452
}
84528453
{
8453-
(
8454-
<Z_ORDER_LAT_LON>
8455-
<LEFT_PAREN>
8456-
columnName = identifier()
8457-
{
8458-
int latPosition = columnList.size();
8459-
IndexColumn lat = (IndexColumn)
8460-
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
8461-
columnName,
8462-
Boolean.FALSE,
8463-
parserContext);
8464-
columnList.add(lat);
8465-
spatialColumnCount = 1;
8466-
}
8467-
[
8468-
<COMMA>
8469-
columnName = identifier()
8470-
{
8471-
IndexColumn lon = (IndexColumn)
8472-
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
8473-
columnName,
8474-
Boolean.FALSE,
8475-
parserContext);
8476-
columnList.add(lon);
8477-
spatialColumnCount = 2;
8478-
}
8479-
]
8480-
<RIGHT_PAREN>
8481-
{
8482-
columnList.applyFunction(IndexColumnList.FunctionType.Z_ORDER_LAT_LON,
8483-
latPosition,
8484-
spatialColumnCount);
8485-
}
8486-
)
8487-
|
8488-
(
8489-
columnName = identifier()
8490-
[ <ASC> | <DESC> { asc = false; } ]
8491-
{
8492-
IndexColumn indexColumn = (IndexColumn)
8493-
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
8494-
columnName,
8495-
asc ? Boolean.TRUE : Boolean.FALSE,
8496-
parserContext);
8497-
columnList.add(indexColumn);
8498-
}
8499-
)
8454+
firstName = identifier()
8455+
( (
8456+
<LEFT_PAREN>
8457+
columnName = identifier()
8458+
{
8459+
firstSpatialColumnPosition = columnList.size();
8460+
IndexColumn lat = (IndexColumn)
8461+
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
8462+
columnName,
8463+
Boolean.FALSE,
8464+
parserContext);
8465+
columnList.add(lat);
8466+
spatialColumnCount = 1;
8467+
}
8468+
[
8469+
<COMMA>
8470+
columnName = identifier()
8471+
{
8472+
IndexColumn lon = (IndexColumn)
8473+
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
8474+
columnName,
8475+
Boolean.FALSE,
8476+
parserContext);
8477+
columnList.add(lon);
8478+
spatialColumnCount = 2;
8479+
}
8480+
]
8481+
<RIGHT_PAREN>
8482+
{
8483+
columnList.applyFunction(IndexColumnList.functionType(firstName),
8484+
firstSpatialColumnPosition,
8485+
spatialColumnCount);
8486+
}
8487+
)
8488+
|
8489+
(
8490+
[ <ASC> | <DESC> { asc = false; } ]
8491+
{
8492+
IndexColumn indexColumn = (IndexColumn)
8493+
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
8494+
firstName,
8495+
asc ? Boolean.TRUE : Boolean.FALSE,
8496+
parserContext);
8497+
columnList.add(indexColumn);
8498+
}
8499+
) )
85008500
}
85018501

85028502
void
@@ -14435,30 +14435,53 @@ groupIndexItemList(IndexColumnList columnList) throws StandardException :
1443514435

1443614436
void groupIndexItem(IndexColumnList columnList) throws StandardException :
1443714437
{
14438-
int latPosition;
14438+
ColumnReference columnReference;
14439+
String[] nameComponents;
14440+
int firstSpatialColumnPosition;
1443914441
int spatialColumnCount;
14442+
boolean asc = true;
1444014443
}
1444114444
{
14442-
(
14443-
<Z_ORDER_LAT_LON>
14444-
<LEFT_PAREN>
14445-
{ latPosition = columnList.size(); }
14446-
unorderedGroupIndexColumnItem(columnList)
14447-
{ spatialColumnCount = 1; }
14448-
[
14445+
nameComponents = groupIndexColumnNameComponents()
14446+
( (
14447+
<LEFT_PAREN>
14448+
{ firstSpatialColumnPosition = columnList.size(); }
14449+
unorderedGroupIndexColumnItem(columnList)
14450+
{ spatialColumnCount = 1; }
14451+
[
1444914452
<COMMA>
1445014453
unorderedGroupIndexColumnItem(columnList)
1445114454
{ spatialColumnCount = 2; }
14452-
]
14453-
<RIGHT_PAREN>
14454-
{
14455-
columnList.applyFunction(IndexColumnList.FunctionType.Z_ORDER_LAT_LON,
14456-
latPosition,
14457-
spatialColumnCount);
14458-
}
14459-
)
14460-
|
14461-
groupIndexColumnItem(columnList)
14455+
]
14456+
<RIGHT_PAREN>
14457+
{
14458+
String functionName = nameComponents[2];
14459+
if (nameComponents[1] != null) {
14460+
functionName = nameComponents[1] + "." + functionName;
14461+
if (nameComponents[0] != null) {
14462+
functionName = nameComponents[0] + "." + functionName;
14463+
}
14464+
throw new StandardException(functionName + " is not a valid function for use in index creation DDL.");
14465+
}
14466+
columnList.applyFunction(IndexColumnList.functionType(functionName),
14467+
firstSpatialColumnPosition,
14468+
spatialColumnCount);
14469+
}
14470+
)
14471+
|
14472+
(
14473+
[ <ASC> | <DESC> { asc = false; } ]
14474+
{
14475+
columnReference = groupIndexColumnNameFromComponents(nameComponents);
14476+
IndexColumn indexColumn = (IndexColumn)
14477+
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
14478+
columnReference.getTableNameNode(),
14479+
columnReference.getColumnName(),
14480+
asc ? Boolean.TRUE : Boolean.FALSE,
14481+
parserContext);
14482+
columnList.add(indexColumn);
14483+
}
14484+
) )
1446214485
}
1446314486

1446414487
void fullTextColumnItemList(IndexColumnList columnList) throws StandardException :
@@ -14482,7 +14505,7 @@ groupIndexColumnItem(IndexColumnList columnList) throws StandardException :
1448214505
ColumnReference groupIndexColumnName;
1448314506
}
1448414507
{
14485-
groupIndexColumnName = groupIndexColumnName(columnList)
14508+
groupIndexColumnName = groupIndexColumnName()
1448614509
[ <ASC> | <DESC> { asc = false; } ]
1448714510
{
1448814511
IndexColumn indexColumn = (IndexColumn)
@@ -14501,7 +14524,7 @@ unorderedGroupIndexColumnItem(IndexColumnList columnList) throws StandardExcepti
1450114524
ColumnReference groupIndexColumnName;
1450214525
}
1450314526
{
14504-
groupIndexColumnName = groupIndexColumnName(columnList)
14527+
groupIndexColumnName = groupIndexColumnName()
1450514528
{
1450614529
IndexColumn indexColumn = (IndexColumn)
1450714530
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
@@ -14514,48 +14537,67 @@ unorderedGroupIndexColumnItem(IndexColumnList columnList) throws StandardExcepti
1451414537
}
1451514538

1451614539
ColumnReference
14517-
groupIndexColumnName(IndexColumnList columnList) throws StandardException :
14540+
groupIndexColumnName() throws StandardException :
14541+
{
14542+
String[] names;
14543+
}
14544+
{
14545+
{
14546+
return groupIndexColumnNameFromComponents(groupIndexColumnNameComponents());
14547+
}
14548+
}
14549+
14550+
ColumnReference
14551+
groupIndexColumnNameFromComponents(String[] names) throws StandardException :
1451814552
{
14519-
String firstName;
14520-
String secondName = null;
14521-
String thirdName = null;
1452214553
}
1452314554
{
14524-
firstName = identifierDeferCheckLength()
14525-
[ LOOKAHEAD( { getToken(1).kind == PERIOD } )
14526-
<PERIOD>
14527-
secondName = identifierDeferCheckLength()
14528-
[ LOOKAHEAD( { getToken(1).kind == PERIOD } )
14529-
<PERIOD>
14530-
thirdName = identifierDeferCheckLength() ] ]
1453114555
{
14532-
if (secondName == null) {
14533-
thirdName = firstName;
14534-
firstName = null;
14535-
}
14536-
else if (thirdName == null) {
14537-
thirdName = secondName;
14538-
secondName = firstName;
14539-
firstName = null;
14540-
}
14541-
if (firstName != null)
14542-
parserContext.checkIdentifierLengthLimit(firstName);
14543-
if (secondName != null)
14544-
parserContext.checkIdentifierLengthLimit(secondName);
14545-
parserContext.checkIdentifierLengthLimit(thirdName);
1454614556
TableName tableName = null;
14547-
if (secondName != null)
14557+
if (names[1] != null)
1454814558
tableName = (TableName)nodeFactory.getNode(NodeTypes.TABLE_NAME,
14549-
firstName,
14550-
secondName,
14559+
names[0],
14560+
names[1],
1455114561
new Integer(nextToLastIdentifierToken.beginOffset),
1455214562
new Integer(nextToLastIdentifierToken.endOffset),
1455314563
parserContext);
1455414564
return (ColumnReference)nodeFactory.getNode(NodeTypes.COLUMN_REFERENCE,
14555-
thirdName,
14565+
names[2],
1455614566
tableName,
1455714567
new Integer(lastIdentifierToken.beginOffset),
1455814568
new Integer(lastIdentifierToken.endOffset),
1455914569
parserContext);
1456014570
}
1456114571
}
14572+
14573+
String[]
14574+
groupIndexColumnNameComponents() throws StandardException :
14575+
{
14576+
String[] names = new String[3];
14577+
}
14578+
{
14579+
names[0] = identifierDeferCheckLength()
14580+
[ LOOKAHEAD( { getToken(1).kind == PERIOD } )
14581+
<PERIOD>
14582+
names[1] = identifierDeferCheckLength()
14583+
[ LOOKAHEAD( { getToken(1).kind == PERIOD } )
14584+
<PERIOD>
14585+
names[2] = identifierDeferCheckLength() ] ]
14586+
{
14587+
if (names[1] == null) {
14588+
names[2] = names[0];
14589+
names[0] = null;
14590+
}
14591+
else if (names[2] == null) {
14592+
names[2] = names[1];
14593+
names[1] = names[0];
14594+
names[0] = null;
14595+
}
14596+
if (names[0] != null)
14597+
parserContext.checkIdentifierLengthLimit(names[0]);
14598+
if (names[1] != null)
14599+
parserContext.checkIdentifierLengthLimit(names[1]);
14600+
parserContext.checkIdentifierLengthLimit(names[2]);
14601+
return names;
14602+
}
14603+
}

src/test/resources/com/foundationdb/sql/parser/alter-table-add-geo-index-1.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tableElementList:
2424
indexColumnList:
2525
com.foundationdb.sql.parser.IndexColumnList@40e40f4c
2626

27-
methodName: Z_ORDER_LAT_LON
27+
methodName: GEO_LAT_LON
2828
firstArg: 0
2929
lastArg: 1
3030
[0]:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
alter table t1 add Unique index idx2 (z_order_lat_lon(c1, c2))
1+
alter table t1 add Unique index idx2 (GEO_LAT_LON(c1, c2))

src/test/resources/com/foundationdb/sql/parser/alter-table-add-geo-index-2.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tableElementList:
2424
indexColumnList:
2525
com.foundationdb.sql.parser.IndexColumnList@40e40f4c
2626

27-
methodName: Z_ORDER_LAT_LON
27+
methodName: GEO_LAT_LON
2828
firstArg: 0
2929
lastArg: 0
3030
[0]:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
alter table t1 add Unique index idx2 (z_order_lat_lon(c1))
1+
alter table t1 add Unique index idx2 (geo_lat_lon(c1))

src/test/resources/com/foundationdb/sql/parser/create-geo-index-1.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ existenceCheck: IF_NOT_EXISTS
1010

1111
com.foundationdb.sql.parser.IndexColumnList@2844916c
1212

13-
methodName: Z_ORDER_LAT_LON
13+
methodName: GEO_LAT_LON
1414
firstArg: 0
1515
lastArg: 1
1616
[0]:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
create index if not exists idx1 on table1 (z_order_lat_lon(c1, c2))
1+
create index if not exists idx1 on table1 (geo_lat_lon(c1, c2))

src/test/resources/com/foundationdb/sql/parser/create-geo-index-2.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ existenceCheck: IF_NOT_EXISTS
1010

1111
com.foundationdb.sql.parser.IndexColumnList@2844916c
1212

13-
methodName: Z_ORDER_LAT_LON
13+
methodName: GEO_LAT_LON
1414
firstArg: 0
1515
lastArg: 0
1616
[0]:

0 commit comments

Comments
 (0)