[NO ISSUE][COMP] Show proper error message with invalid type
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
While creating dataset without type spec, if a invalid type is used,
a null pointer exception was shown. With this patch we now show a proper
error message.
Change-Id: I7edfe4f52c20da7f667c9560edea50fd7112932f
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17746
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Peeyush Gupta <peeyush.gupta@couchbase.com>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java
index 967f99f..77c1a9d 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java
@@ -146,6 +146,10 @@
String typeName =
((TypeReferenceExpression) partitioningExprTypes.get(0)).getIdent().second.getValue();
fieldType = BuiltinTypeMap.getBuiltinType(typeName);
+ if (fieldType == null) {
+ throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_KEY_TYPE, sourceLoc, typeName,
+ keyKindDisplayName);
+ }
} else {
String unTypeField = fieldName.get(0) == null ? "" : fieldName.get(0);
throw new CompilationException(ErrorCode.COMPILATION_FIELD_NOT_FOUND, sourceLoc,
@@ -170,6 +174,10 @@
String typeName =
((TypeReferenceExpression) partitioningExprTypes.get(i)).getIdent().second.getValue();
fieldType = BuiltinTypeMap.getBuiltinType(typeName);
+ if (fieldType == null) {
+ throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_KEY_TYPE, sourceLoc, typeName,
+ keyKindDisplayName);
+ }
computedPartitioningExprTypes.add(fieldType);
} else {
fieldType = computedPartitioningExprTypes.get(i);