diff --git a/sql-gremlin/src/main/java/org/twilmes/sql/gremlin/adapter/converter/ast/nodes/GremlinSqlFactory.java b/sql-gremlin/src/main/java/org/twilmes/sql/gremlin/adapter/converter/ast/nodes/GremlinSqlFactory.java index 464e11fe..75db0ef3 100644 --- a/sql-gremlin/src/main/java/org/twilmes/sql/gremlin/adapter/converter/ast/nodes/GremlinSqlFactory.java +++ b/sql-gremlin/src/main/java/org/twilmes/sql/gremlin/adapter/converter/ast/nodes/GremlinSqlFactory.java @@ -137,7 +137,9 @@ public static T createNodeCheckType(final SqlNode sqlNode, final Class 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); diff --git a/sql-gremlin/src/main/java/org/twilmes/sql/gremlin/adapter/util/SqlGremlinError.java b/sql-gremlin/src/main/java/org/twilmes/sql/gremlin/adapter/util/SqlGremlinError.java index efb77a38..8d103b32 100644 --- a/sql-gremlin/src/main/java/org/twilmes/sql/gremlin/adapter/util/SqlGremlinError.java +++ b/sql-gremlin/src/main/java/org/twilmes/sql/gremlin/adapter/util/SqlGremlinError.java @@ -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; diff --git a/sql-gremlin/src/main/resources/error-messages_en.properties b/sql-gremlin/src/main/resources/error-messages_en.properties index bf168503..6c56ae11 100644 --- a/sql-gremlin/src/main/resources/error-messages_en.properties +++ b/sql-gremlin/src/main/resources/error-messages_en.properties @@ -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. \ No newline at end of file +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." diff --git a/sql-gremlin/src/test/java/org/twilmes/sql/gremlin/adapter/GremlinSqlAggregateTest.java b/sql-gremlin/src/test/java/org/twilmes/sql/gremlin/adapter/GremlinSqlAggregateTest.java index 7b994610..422985ba 100644 --- a/sql-gremlin/src/test/java/org/twilmes/sql/gremlin/adapter/GremlinSqlAggregateTest.java +++ b/sql-gremlin/src/test/java/org/twilmes/sql/gremlin/adapter/GremlinSqlAggregateTest.java @@ -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))); - } } diff --git a/sql-gremlin/src/test/java/org/twilmes/sql/gremlin/adapter/GremlinSqlNotSupportedTest.java b/sql-gremlin/src/test/java/org/twilmes/sql/gremlin/adapter/GremlinSqlNotSupportedTest.java index 4df04be4..e81ef91a 100644 --- a/sql-gremlin/src/test/java/org/twilmes/sql/gremlin/adapter/GremlinSqlNotSupportedTest.java +++ b/sql-gremlin/src/test/java/org/twilmes/sql/gremlin/adapter/GremlinSqlNotSupportedTest.java @@ -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 { @@ -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"); } }