Skip to content

Commit

Permalink
Generalized grammar to allow for function names inside of index DDL, not
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geophile committed Jan 8, 2015
1 parent 00b0d1d commit ae635be
Show file tree
Hide file tree
Showing 25 changed files with 171 additions and 123 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>com.foundationdb</groupId>
<artifactId>fdb-sql-parser</artifactId>
<version>1.6.0-SNAPSHOT</version>
<version>1.6.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>FoundationDB SQL Parser</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class IndexColumnList extends QueryTreeNodeList<IndexColumn>

public static enum FunctionType
{
Z_ORDER_LAT_LON, FULL_TEXT
GEO_LAT_LON, FULL_TEXT
// ADD MORE AS NEEDED
}

Expand Down Expand Up @@ -100,4 +100,10 @@ public String toString()
functionApplication.functionType, functionApplication.firstArgumentPosition, functionApplication.lastArgumentPosition)
: super.toString();
}

public static FunctionType functionType(String functionName)
{
return Enum.valueOf(FunctionType.class, functionName.trim().toUpperCase());
}

}
240 changes: 141 additions & 99 deletions src/main/javacc/SQLGrammar.jj
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,6 @@ TOKEN [IGNORE_CASE] :
| <XMLPARSE: "xmlparse">
| <XMLQUERY: "xmlquery">
| <XMLSERIALIZE: "xmlserialize">
| <Z_ORDER_LAT_LON: "z_order_lat_lon">
}

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

void indexItem(IndexColumnList columnList) throws StandardException :
{
String columnName;
String firstName = null;
String columnName = null;
boolean asc = true;
int spatialColumnCount;
int firstSpatialColumnPosition = -1;
int spatialColumnCount = -1;
}
{
(
<Z_ORDER_LAT_LON>
<LEFT_PAREN>
columnName = identifier()
{
int latPosition = columnList.size();
IndexColumn lat = (IndexColumn)
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
columnName,
Boolean.FALSE,
parserContext);
columnList.add(lat);
spatialColumnCount = 1;
}
[
<COMMA>
columnName = identifier()
{
IndexColumn lon = (IndexColumn)
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
columnName,
Boolean.FALSE,
parserContext);
columnList.add(lon);
spatialColumnCount = 2;
}
]
<RIGHT_PAREN>
{
columnList.applyFunction(IndexColumnList.FunctionType.Z_ORDER_LAT_LON,
latPosition,
spatialColumnCount);
}
)
|
(
columnName = identifier()
[ <ASC> | <DESC> { asc = false; } ]
{
IndexColumn indexColumn = (IndexColumn)
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
columnName,
asc ? Boolean.TRUE : Boolean.FALSE,
parserContext);
columnList.add(indexColumn);
}
)
firstName = identifier()
( (
<LEFT_PAREN>
columnName = identifier()
{
firstSpatialColumnPosition = columnList.size();
IndexColumn lat = (IndexColumn)
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
columnName,
Boolean.FALSE,
parserContext);
columnList.add(lat);
spatialColumnCount = 1;
}
[
<COMMA>
columnName = identifier()
{
IndexColumn lon = (IndexColumn)
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
columnName,
Boolean.FALSE,
parserContext);
columnList.add(lon);
spatialColumnCount = 2;
}
]
<RIGHT_PAREN>
{
columnList.applyFunction(IndexColumnList.functionType(firstName),
firstSpatialColumnPosition,
spatialColumnCount);
}
)
|
(
[ <ASC> | <DESC> { asc = false; } ]
{
IndexColumn indexColumn = (IndexColumn)
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
firstName,
asc ? Boolean.TRUE : Boolean.FALSE,
parserContext);
columnList.add(indexColumn);
}
) )
}

void
Expand Down Expand Up @@ -14435,30 +14435,53 @@ groupIndexItemList(IndexColumnList columnList) throws StandardException :

void groupIndexItem(IndexColumnList columnList) throws StandardException :
{
int latPosition;
ColumnReference columnReference;
String[] nameComponents;
int firstSpatialColumnPosition;
int spatialColumnCount;
boolean asc = true;
}
{
(
<Z_ORDER_LAT_LON>
<LEFT_PAREN>
{ latPosition = columnList.size(); }
unorderedGroupIndexColumnItem(columnList)
{ spatialColumnCount = 1; }
[
nameComponents = groupIndexColumnNameComponents()
( (
<LEFT_PAREN>
{ firstSpatialColumnPosition = columnList.size(); }
unorderedGroupIndexColumnItem(columnList)
{ spatialColumnCount = 1; }
[
<COMMA>
unorderedGroupIndexColumnItem(columnList)
{ spatialColumnCount = 2; }
]
<RIGHT_PAREN>
{
columnList.applyFunction(IndexColumnList.FunctionType.Z_ORDER_LAT_LON,
latPosition,
spatialColumnCount);
}
)
|
groupIndexColumnItem(columnList)
]
<RIGHT_PAREN>
{
String functionName = nameComponents[2];
if (nameComponents[1] != null) {
functionName = nameComponents[1] + "." + functionName;
if (nameComponents[0] != null) {
functionName = nameComponents[0] + "." + functionName;
}
throw new StandardException(functionName + " is not a valid function for use in index creation DDL.");
}
columnList.applyFunction(IndexColumnList.functionType(functionName),
firstSpatialColumnPosition,
spatialColumnCount);
}
)
|
(
[ <ASC> | <DESC> { asc = false; } ]
{
columnReference = groupIndexColumnNameFromComponents(nameComponents);
IndexColumn indexColumn = (IndexColumn)
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
columnReference.getTableNameNode(),
columnReference.getColumnName(),
asc ? Boolean.TRUE : Boolean.FALSE,
parserContext);
columnList.add(indexColumn);
}
) )
}

void fullTextColumnItemList(IndexColumnList columnList) throws StandardException :
Expand All @@ -14482,7 +14505,7 @@ groupIndexColumnItem(IndexColumnList columnList) throws StandardException :
ColumnReference groupIndexColumnName;
}
{
groupIndexColumnName = groupIndexColumnName(columnList)
groupIndexColumnName = groupIndexColumnName()
[ <ASC> | <DESC> { asc = false; } ]
{
IndexColumn indexColumn = (IndexColumn)
Expand All @@ -14501,7 +14524,7 @@ unorderedGroupIndexColumnItem(IndexColumnList columnList) throws StandardExcepti
ColumnReference groupIndexColumnName;
}
{
groupIndexColumnName = groupIndexColumnName(columnList)
groupIndexColumnName = groupIndexColumnName()
{
IndexColumn indexColumn = (IndexColumn)
nodeFactory.getNode(NodeTypes.INDEX_COLUMN,
Expand All @@ -14514,48 +14537,67 @@ unorderedGroupIndexColumnItem(IndexColumnList columnList) throws StandardExcepti
}

ColumnReference
groupIndexColumnName(IndexColumnList columnList) throws StandardException :
groupIndexColumnName() throws StandardException :
{
String[] names;
}
{
{
return groupIndexColumnNameFromComponents(groupIndexColumnNameComponents());
}
}

ColumnReference
groupIndexColumnNameFromComponents(String[] names) throws StandardException :
{
String firstName;
String secondName = null;
String thirdName = null;
}
{
firstName = identifierDeferCheckLength()
[ LOOKAHEAD( { getToken(1).kind == PERIOD } )
<PERIOD>
secondName = identifierDeferCheckLength()
[ LOOKAHEAD( { getToken(1).kind == PERIOD } )
<PERIOD>
thirdName = identifierDeferCheckLength() ] ]
{
if (secondName == null) {
thirdName = firstName;
firstName = null;
}
else if (thirdName == null) {
thirdName = secondName;
secondName = firstName;
firstName = null;
}
if (firstName != null)
parserContext.checkIdentifierLengthLimit(firstName);
if (secondName != null)
parserContext.checkIdentifierLengthLimit(secondName);
parserContext.checkIdentifierLengthLimit(thirdName);
TableName tableName = null;
if (secondName != null)
if (names[1] != null)
tableName = (TableName)nodeFactory.getNode(NodeTypes.TABLE_NAME,
firstName,
secondName,
names[0],
names[1],
new Integer(nextToLastIdentifierToken.beginOffset),
new Integer(nextToLastIdentifierToken.endOffset),
parserContext);
return (ColumnReference)nodeFactory.getNode(NodeTypes.COLUMN_REFERENCE,
thirdName,
names[2],
tableName,
new Integer(lastIdentifierToken.beginOffset),
new Integer(lastIdentifierToken.endOffset),
parserContext);
}
}

String[]
groupIndexColumnNameComponents() throws StandardException :
{
String[] names = new String[3];
}
{
names[0] = identifierDeferCheckLength()
[ LOOKAHEAD( { getToken(1).kind == PERIOD } )
<PERIOD>
names[1] = identifierDeferCheckLength()
[ LOOKAHEAD( { getToken(1).kind == PERIOD } )
<PERIOD>
names[2] = identifierDeferCheckLength() ] ]
{
if (names[1] == null) {
names[2] = names[0];
names[0] = null;
}
else if (names[2] == null) {
names[2] = names[1];
names[1] = names[0];
names[0] = null;
}
if (names[0] != null)
parserContext.checkIdentifierLengthLimit(names[0]);
if (names[1] != null)
parserContext.checkIdentifierLengthLimit(names[1]);
parserContext.checkIdentifierLengthLimit(names[2]);
return names;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tableElementList:
indexColumnList:
com.foundationdb.sql.parser.IndexColumnList@40e40f4c

methodName: Z_ORDER_LAT_LON
methodName: GEO_LAT_LON
firstArg: 0
lastArg: 1
[0]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
alter table t1 add Unique index idx2 (z_order_lat_lon(c1, c2))
alter table t1 add Unique index idx2 (GEO_LAT_LON(c1, c2))
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tableElementList:
indexColumnList:
com.foundationdb.sql.parser.IndexColumnList@40e40f4c

methodName: Z_ORDER_LAT_LON
methodName: GEO_LAT_LON
firstArg: 0
lastArg: 0
[0]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
alter table t1 add Unique index idx2 (z_order_lat_lon(c1))
alter table t1 add Unique index idx2 (geo_lat_lon(c1))
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ existenceCheck: IF_NOT_EXISTS

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

methodName: Z_ORDER_LAT_LON
methodName: GEO_LAT_LON
firstArg: 0
lastArg: 1
[0]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create index if not exists idx1 on table1 (z_order_lat_lon(c1, c2))
create index if not exists idx1 on table1 (geo_lat_lon(c1, c2))
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ existenceCheck: IF_NOT_EXISTS

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

methodName: Z_ORDER_LAT_LON
methodName: GEO_LAT_LON
firstArg: 0
lastArg: 0
[0]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create index if not exists idx1 on table1 (z_order_lat_lon(c1))
create index if not exists idx1 on table1 (geo_lat_lon(c1))
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tableElementList:
indexColumnList:
com.foundationdb.sql.parser.IndexColumnList@63deebc8

methodName: Z_ORDER_LAT_LON
methodName: GEO_LAT_LON
firstArg: 0
lastArg: 1
[0]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table t1 (c1 int, c2 double, c3 bigint, index indx1 (z_order_lat_lon(c1, c2)))
create table t1 (c1 int, c2 double, c3 bigint, index indx1 (geo_lat_lon(c1, c2)))
Loading

0 comments on commit ae635be

Please sign in to comment.