ASTERIXDB-1331: fix the type computer for string-length.
Change-Id: Ia21a29049364bd2f99bfd766efdd1518aeffe79f
Reviewed-on: https://asterix-gerrit.ics.uci.edu/689
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <michael.blow@couchbase.com>
Reviewed-by: Ian Maxon <imaxon@apache.org>
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.query.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.query.sqlpp
new file mode 100644
index 0000000..8ccf4ef
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/** This test case is to verify the fix for ASTERIXDB-1331. */
+
+USE TinySocial;
+
+SELECT ELEMENT avg((
+select element "string-length"(message.message)
+FROM FacebookMessages AS message
+WHERE message."in-response-to" >= 1 and
+ message."in-response-to" < 11
+));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.query.sqlpp b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.query.sqlpp
new file mode 100644
index 0000000..7c22f59
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.query.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE TinySocial;
+
+SELECT ELEMENT avg((
+select element "string-length"(message.message)
+FROM FacebookMessages AS message
+WHERE message."in-response-to" >= 1 and
+ message."in-response-to" < 11
+));
+
diff --git a/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.adm b/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.adm
new file mode 100644
index 0000000..21f0477
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.adm
@@ -0,0 +1 @@
+42.666666666666664d
diff --git a/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite/tinysocial-suite.25.adm b/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite/tinysocial-suite.25.adm
new file mode 100644
index 0000000..21f0477
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite/tinysocial-suite.25.adm
@@ -0,0 +1 @@
+42.666666666666664d
diff --git a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.ast b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.ast
new file mode 100644
index 0000000..cf21764
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite-open/query-ASTERIXDB-1331.25.ast
@@ -0,0 +1,42 @@
+DataverseUse TinySocial
+Query:
+SELECT ELEMENT [
+FunctionCall TinySocial.avg@1[
+ (
+ SELECT ELEMENT [
+ FunctionCall TinySocial.string-length@1[
+ FieldAccessor [
+ Variable [ Name=message ]
+ Field=message
+ ]
+ ]
+ ]
+ FROM [ FunctionCall Metadata.dataset@1[
+ LiteralExpr [STRING] [FacebookMessages]
+ ]
+ AS
+ Variable [ Name=message ]
+ ]
+ Where
+ OperatorExpr [
+ OperatorExpr [
+ FieldAccessor [
+ Variable [ Name=message ]
+ Field=in-response-to
+ ]
+ >=
+ LiteralExpr [LONG] [1]
+ ]
+ and
+ OperatorExpr [
+ FieldAccessor [
+ Variable [ Name=message ]
+ Field=in-response-to
+ ]
+ <
+ LiteralExpr [LONG] [11]
+ ]
+ ]
+ )
+]
+]
diff --git a/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.ast b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.ast
new file mode 100644
index 0000000..cf21764
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/tinysocial/tinysocial-suite/tinysocial-suite.25.ast
@@ -0,0 +1,42 @@
+DataverseUse TinySocial
+Query:
+SELECT ELEMENT [
+FunctionCall TinySocial.avg@1[
+ (
+ SELECT ELEMENT [
+ FunctionCall TinySocial.string-length@1[
+ FieldAccessor [
+ Variable [ Name=message ]
+ Field=message
+ ]
+ ]
+ ]
+ FROM [ FunctionCall Metadata.dataset@1[
+ LiteralExpr [STRING] [FacebookMessages]
+ ]
+ AS
+ Variable [ Name=message ]
+ ]
+ Where
+ OperatorExpr [
+ OperatorExpr [
+ FieldAccessor [
+ Variable [ Name=message ]
+ Field=in-response-to
+ ]
+ >=
+ LiteralExpr [LONG] [1]
+ ]
+ and
+ OperatorExpr [
+ FieldAccessor [
+ Variable [ Name=message ]
+ Field=in-response-to
+ ]
+ <
+ LiteralExpr [LONG] [11]
+ ]
+ ]
+ )
+]
+]
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UnaryStringInt64OrNullTypeComputer.java b/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UnaryStringInt64OrNullTypeComputer.java
index b0d8bce..f41a719 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UnaryStringInt64OrNullTypeComputer.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UnaryStringInt64OrNullTypeComputer.java
@@ -47,8 +47,9 @@
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
- if (fce.getArguments().isEmpty())
+ if (fce.getArguments().isEmpty()) {
throw new AlgebricksException("Wrong Argument Number.");
+ }
ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
IAType t0;
try {
@@ -56,10 +57,12 @@
} catch (AlgebricksException e) {
throw new AlgebricksException(e);
}
- if (t0.getTypeTag() != ATypeTag.NULL
- && t0.getTypeTag() != ATypeTag.STRING
- && (t0.getTypeTag() == ATypeTag.UNION && !((AUnionType) t0).getUnionList()
- .contains(BuiltinType.ASTRING))) {
+ if (t0.getTypeTag() == ATypeTag.ANY) {
+ return BuiltinType.ANY;
+ }
+
+ if (t0.getTypeTag() != ATypeTag.NULL && t0.getTypeTag() != ATypeTag.STRING && (t0.getTypeTag() == ATypeTag.UNION
+ && !((AUnionType) t0).getUnionList().contains(BuiltinType.ASTRING))) {
throw new NotImplementedException("Expects String Type.");
}