[ASTERIXDB-2922][FUN] Fix get_type function bug w/ multiple records.
- user mode changes: no
- storage format changes: no
- interface changes: no
Previously, get_type used a string builder that would retain the results
of all past records. We now use the raw string from the type instance
itself.
Change-Id: I9564bcdeb94dd141a03cc12a2f7a61f1e57d250b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12203
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Glenn Galvizo <ggalvizo@uci.edu>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.2.query.sqlpp
new file mode 100644
index 0000000..b4c4e4f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.2.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+FROM [
+ { "f": "a" },
+ { "f": "b" },
+ { "f": "c" }
+] AS D
+SELECT GET_TYPE(D.f) AS dType;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.3.ddl.sqlpp
new file mode 100644
index 0000000..5606270
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.3.ddl.sqlpp
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.AllType as
+{
+ t1: [string],
+ t2: binary,
+ t3: boolean,
+ t4: circle,
+ t5: date,
+ t6: datetime,
+ t7: duration,
+ t8: interval,
+ t9: line,
+ t10: {{string}},
+ t11: point,
+ t12: polygon,
+ t13: rectangle,
+ t14: string,
+ t15: time,
+ t16: uuid
+};
+
+create dataset `All` (AllType) primary key t16 autogenerated;
+
+insert into `All` [{
+ "t1": ["a", "b"],
+ "t2": hex("ABCDEF0123456789"),
+ "t3": false,
+ "t4": circle("30.0,70.0 5.0"),
+ "t5": date("-19700101"),
+ "t6": datetime("2013-01-01T12:12:12.039Z"),
+ "t7": duration("P100Y12MT12M"),
+ "t8": interval(date("2013-01-01"), date("20130505")),
+ "t9": line("30.0,70.0 50.0,90.0"),
+ "t10": {{"a", "b"}},
+ "t11": point("1,2"),
+ "t12": polygon("1.0,1.0 2.0,2.0 3.0,3.0 4.0,4.0"),
+ "t13": rectangle("30.0,70.0 50.0,90.0"),
+ "t14": "abcde",
+ "t15": time("12:12:12.039Z")
+},
+{
+ "t1": ["a", "b"],
+ "t2": hex("ABCDEF0123456789"),
+ "t3": false,
+ "t4": circle("30.0,70.0 5.0"),
+ "t5": date("-19700101"),
+ "t6": datetime("2013-01-01T12:12:12.039Z"),
+ "t7": duration("P100Y12MT12M"),
+ "t8": interval(date("2013-01-01"), date("20130505")),
+ "t9": line("30.0,70.0 50.0,90.0"),
+ "t10": {{"a", "b"}},
+ "t11": point("1,2"),
+ "t12": polygon("1.0,1.0 2.0,2.0 3.0,3.0 4.0,4.0"),
+ "t13": rectangle("30.0,70.0 50.0,90.0"),
+ "t14": "abcde",
+ "t15": time("12:12:12.039Z")
+}];
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.4.query.sqlpp
new file mode 100644
index 0000000..dbec25f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/gettype/gettype.4.query.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * 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 test;
+
+SELECT VALUE {
+ "t1": get_type(t1),
+ "t2": get_type(t2),
+ "t3": get_type(t3),
+ "t4": get_type(t4),
+ "t5": get_type(t5),
+ "t6": get_type(t6),
+ "t7": get_type(t7),
+ "t8": get_type(t8),
+ "t9": get_type(t9),
+ "t10": get_type(t10),
+ "t11": get_type(t11),
+ "t12": get_type(t12),
+ "t13": get_type(t13),
+ "t14": get_type(t14),
+ "t15": get_type(t15),
+ "t16": get_type(t16)
+}
+FROM `All`;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/gettype/gettype.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/gettype/gettype.2.adm
new file mode 100644
index 0000000..ad79b3b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/gettype/gettype.2.adm
@@ -0,0 +1,3 @@
+{ "dType": "string" }
+{ "dType": "string" }
+{ "dType": "string" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/gettype/gettype.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/gettype/gettype.3.adm
new file mode 100644
index 0000000..5154d50
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/gettype/gettype.3.adm
@@ -0,0 +1,2 @@
+{ "t1": "array", "t2": "binary", "t3": "boolean", "t4": "circle", "t5": "date", "t6": "datetime", "t7": "duration", "t8": "interval", "t9": "line", "t10": "multiset", "t11": "point", "t12": "polygon", "t13": "rectangle", "t14": "string", "t15": "time", "t16": "uuid" }
+{ "t1": "array", "t2": "binary", "t3": "boolean", "t4": "circle", "t5": "date", "t6": "datetime", "t7": "duration", "t8": "interval", "t9": "line", "t10": "multiset", "t11": "point", "t12": "polygon", "t13": "rectangle", "t14": "string", "t15": "time", "t16": "uuid" }
\ No newline at end of file
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetTypeDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetTypeDescriptor.java
index 843ef62..cbb253a 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetTypeDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetTypeDescriptor.java
@@ -51,9 +51,7 @@
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput dataOutput = resultStorage.getDataOutput();
private IScalarEvaluator inputEval = args[0].createScalarEvaluator(ctx);
- final IPointable inputArg = new VoidPointable();
-
- private StringBuilder stringBuilder = new StringBuilder();
+ private final IPointable inputArg = new VoidPointable();
private final UTF8StringWriter writer = new UTF8StringWriter();
@Override
@@ -61,13 +59,11 @@
resultStorage.reset();
inputEval.evaluate(tuple, inputArg);
- byte[] bytes = inputArg.getByteArray();
- int offset = inputArg.getStartOffset();
- stringBuilder.append(ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]].toString());
-
try {
+ byte[] bytes = inputArg.getByteArray();
+ int offset = inputArg.getStartOffset();
dataOutput.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
- writer.writeUTF8(stringBuilder.toString(), dataOutput);
+ writer.writeUTF8(ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]].toString(), dataOutput);
} catch (IOException e) {
throw HyracksDataException.create(e);
}