Skip to content

Commit

Permalink
Merge pull request #92 from aws/lyndon/cast-npe
Browse files Browse the repository at this point in the history
AN-915 fix CAST null pointer exception
  • Loading branch information
lyndonbauto committed Dec 8, 2021
2 parents 7936177 + f5c49d8 commit 4b0ae1a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public static <T> T createNodeCheckType(final SqlNode sqlNode, final Class<T> cl

public static GremlinSqlSelect createSelect(final SqlSelect selectRoot, final GraphTraversalSource g)
throws SQLException {
if (selectRoot.getFrom() instanceof SqlJoin) {
if (selectRoot.getFrom() == null) {
throw SqlGremlinError.createNotSupported(SqlGremlinError.UNSUPPORTED_LITERAL_EXPRESSION);
} else if (selectRoot.getFrom() instanceof SqlJoin) {
return new GremlinSqlSelectMulti(selectRoot, (SqlJoin) selectRoot.getFrom(), sqlMetadata, g);
} else if (selectRoot.getFrom() instanceof SqlBasicCall) {
return new GremlinSqlSelectSingle(selectRoot, (SqlBasicCall) selectRoot.getFrom(), sqlMetadata, g);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public enum SqlGremlinError {
UNEXPECTED_JOIN_NODES,
NO_JOIN_COLUMN,
NOT_LOGICAL_FILTER,
OFFSET_NOT_SUPPORTED;
OFFSET_NOT_SUPPORTED,
UNSUPPORTED_LITERAL_EXPRESSION;

private static final ResourceBundle RESOURCE;

Expand Down
3 changes: 2 additions & 1 deletion sql-gremlin/src/main/resources/error-messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ WHERE_BASIC_LITERALS=Unsupported: Unsupported WHERE clause - Only basic literal
UNEXPECTED_JOIN_NODES=Error: Expected nodes in join comparison to be GremlinSqlIdentifiers.
NO_JOIN_COLUMN=Error: Expected to find join column for renamed table.
NOT_LOGICAL_FILTER=Error: Cannot convert %s to %s.
OFFSET_NOT_SUPPORTED=Unsupported: OFFSET is not currently supported.
OFFSET_NOT_SUPPORTED=Unsupported: OFFSET is not currently supported.
UNSUPPORTED_LITERAL_EXPRESSION="Unsupported: Raw literal expressions without any tables referenced are now supported at this time."
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,5 @@ public void testCountWhereGroupBy() throws SQLException {
columns("wentToSpace", "COUNT(age)"), rows(r(false, 3L)));
runQueryTestResults("SELECT wentToSpace, COUNT(age) FROM person WHERE age > 31 AND wentToSpace = FALSE GROUP BY wentToSpace",
columns("wentToSpace", "COUNT(age)"), rows(r(false, 1L)));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@

package org.twilmes.sql.gremlin.adapter;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.twilmes.sql.gremlin.adapter.util.SqlGremlinError;

import java.sql.SQLException;

public class GremlinSqlNotSupportedTest extends GremlinSqlBaseTest {
Expand All @@ -49,9 +47,11 @@ public void testSubQuery() throws SQLException {
SqlGremlinError.UNKNOWN_OPERATOR, "SCALAR_QUERY");
}

// TODO: Handle CAST
@Disabled
@Test
public void testCast() throws SQLException {
runNotSupportedQueryTestThrows("SELECT CAST(17 AS varchar)", null);
runNotSupportedQueryTestThrows("SELECT CAST(17 AS varchar)",
SqlGremlinError.UNSUPPORTED_LITERAL_EXPRESSION);
runQueryTestThrows("SELECT CAST(person.age as CHAR) FROM person",
SqlGremlinError.UNKNOWN_OPERATOR, "CAST");
}
}

0 comments on commit 4b0ae1a

Please sign in to comment.