Repository: asterixdb Updated Branches: refs/heads/master ecba52e0b -> 8fa8b7afe
Add type check functions and their docs, including: -isboolean (isbool) -isnumber (isnum) -isstring (istr) -isarray -isobject (isobj) Change-Id: Id12067dbd89f74a6c1248eb7ac6504400a67cbf6 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1257 Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Till Westmann <ti...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/8fa8b7af Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/8fa8b7af Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/8fa8b7af Branch: refs/heads/master Commit: 8fa8b7afe5644882cac12d7cf5087cf01f2f3fe5 Parents: ecba52e Author: Yingyi Bu <yin...@couchbase.com> Authored: Fri Oct 7 11:10:19 2016 -0700 Committer: Yingyi Bu <buyin...@gmail.com> Committed: Fri Oct 7 20:19:48 2016 -0700 ---------------------------------------------------------------------- .../translator/util/FunctionCollection.java | 12 + .../interval_overlapping.3.adm | 35 --- .../interval_overlapping.4.adm | 35 --- .../types/isarray/isarray.1.query.sqlpp | 30 +++ .../types/isboolean/isboolean.1.query.sqlpp | 30 +++ .../types/isnumber/isnumber.1.query.sqlpp | 31 +++ .../types/isobject/isobject.1.query.sqlpp | 30 +++ .../types/isstring/isstring.1.query.sqlpp | 30 +++ .../results/types/isarray/isarray.1.adm | 1 + .../results/types/isboolean/isboolean.1.adm | 1 + .../results/types/isnumber/isnumber.1.adm | 1 + .../results/types/isobject/isobject.1.adm | 1 + .../results/types/isstring/isstring.1.adm | 1 + .../resources/runtimets/testsuite_sqlpp.xml | 25 ++ asterixdb/asterix-doc/pom.xml | 4 +- .../src/main/markdown/builtins/0_toc.md | 3 +- .../src/main/markdown/builtins/11_others.md | 249 ------------------ .../src/main/markdown/builtins/11_type.md | 263 +++++++++++++++++++ .../src/main/markdown/builtins/12_misc.md | 185 +++++++++++++ .../lang/common/util/CommonFunctionMapUtil.java | 14 + .../om/functions/AsterixBuiltinFunctions.java | 15 ++ .../evaluators/functions/IsArrayDescriptor.java | 68 +++++ .../functions/IsBooleanDescriptor.java | 68 +++++ .../functions/IsNumberDescriptor.java | 73 +++++ .../functions/IsObjectDescriptor.java | 68 +++++ .../functions/IsStringDescriptor.java | 68 +++++ 26 files changed, 1019 insertions(+), 322 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java index 2482121..dd45c86 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java @@ -157,8 +157,13 @@ import org.apache.asterix.runtime.evaluators.functions.GramTokensDescriptor; import org.apache.asterix.runtime.evaluators.functions.HashedGramTokensDescriptor; import org.apache.asterix.runtime.evaluators.functions.HashedWordTokensDescriptor; import org.apache.asterix.runtime.evaluators.functions.InjectFailureDescriptor; +import org.apache.asterix.runtime.evaluators.functions.IsArrayDescriptor; +import org.apache.asterix.runtime.evaluators.functions.IsBooleanDescriptor; import org.apache.asterix.runtime.evaluators.functions.IsMissingDescriptor; import org.apache.asterix.runtime.evaluators.functions.IsNullDescriptor; +import org.apache.asterix.runtime.evaluators.functions.IsNumberDescriptor; +import org.apache.asterix.runtime.evaluators.functions.IsObjectDescriptor; +import org.apache.asterix.runtime.evaluators.functions.IsStringDescriptor; import org.apache.asterix.runtime.evaluators.functions.IsSystemNullDescriptor; import org.apache.asterix.runtime.evaluators.functions.IsUnknownDescriptor; import org.apache.asterix.runtime.evaluators.functions.LenDescriptor; @@ -666,6 +671,13 @@ public class FunctionCollection { functionsToInjectUnkownHandling.add(GetOverlappingIntervalDescriptor.FACTORY); functionsToInjectUnkownHandling.add(DurationFromIntervalDescriptor.FACTORY); + // Type functions. + functionsToInjectUnkownHandling.add(IsBooleanDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(IsNumberDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(IsStringDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(IsArrayDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(IsObjectDescriptor.FACTORY); + // Cast function functionsToInjectUnkownHandling.add(CastTypeDescriptor.FACTORY); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/rttest/results/temporal/interval_joins/interval_overlapping/interval_overlapping.3.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/rttest/results/temporal/interval_joins/interval_overlapping/interval_overlapping.3.adm b/asterixdb/asterix-app/rttest/results/temporal/interval_joins/interval_overlapping/interval_overlapping.3.adm deleted file mode 100644 index 4ecd143..0000000 --- a/asterixdb/asterix-app/rttest/results/temporal/interval_joins/interval_overlapping/interval_overlapping.3.adm +++ /dev/null @@ -1,35 +0,0 @@ -{ "staff": "Alex", "student": "Charles" } -{ "staff": "Alex", "student": "Frank" } -{ "staff": "Alex", "student": "Karen" } -{ "staff": "Alex", "student": "Mary" } -{ "staff": "Alex", "student": "Steve" } -{ "staff": "Elisabeth", "student": "Charles" } -{ "staff": "Elisabeth", "student": "Frank" } -{ "staff": "Elisabeth", "student": "Karen" } -{ "staff": "Elisabeth", "student": "Mary" } -{ "staff": "Elisabeth", "student": "Olga" } -{ "staff": "Elisabeth", "student": "Steve" } -{ "staff": "Elisabeth", "student": "Tess" } -{ "staff": "Franklin", "student": "Karen" } -{ "staff": "Franklin", "student": "Mary" } -{ "staff": "Franklin", "student": "Steve" } -{ "staff": "Franklin", "student": "Tess" } -{ "staff": "Henry", "student": "Charles" } -{ "staff": "Henry", "student": "Frank" } -{ "staff": "Henry", "student": "Karen" } -{ "staff": "Henry", "student": "Mary" } -{ "staff": "Henry", "student": "Steve" } -{ "staff": "Maryann", "student": "Karen" } -{ "staff": "Maryann", "student": "Steve" } -{ "staff": "Maryann", "student": "Tess" } -{ "staff": "Vicky", "student": "Charles" } -{ "staff": "Vicky", "student": "Frank" } -{ "staff": "Vicky", "student": "Karen" } -{ "staff": "Vicky", "student": "Mary" } -{ "staff": "Vicky", "student": "Olga" } -{ "staff": "Vicky", "student": "Steve" } -{ "staff": "Vicky", "student": "Tess" } -{ "staff": "Zack", "student": "Charles" } -{ "staff": "Zack", "student": "Frank" } -{ "staff": "Zack", "student": "Mary" } -{ "staff": "Zack", "student": "Olga" } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/rttest/results/temporal/interval_joins/interval_overlapping/interval_overlapping.4.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/rttest/results/temporal/interval_joins/interval_overlapping/interval_overlapping.4.adm b/asterixdb/asterix-app/rttest/results/temporal/interval_joins/interval_overlapping/interval_overlapping.4.adm deleted file mode 100644 index 4ecd143..0000000 --- a/asterixdb/asterix-app/rttest/results/temporal/interval_joins/interval_overlapping/interval_overlapping.4.adm +++ /dev/null @@ -1,35 +0,0 @@ -{ "staff": "Alex", "student": "Charles" } -{ "staff": "Alex", "student": "Frank" } -{ "staff": "Alex", "student": "Karen" } -{ "staff": "Alex", "student": "Mary" } -{ "staff": "Alex", "student": "Steve" } -{ "staff": "Elisabeth", "student": "Charles" } -{ "staff": "Elisabeth", "student": "Frank" } -{ "staff": "Elisabeth", "student": "Karen" } -{ "staff": "Elisabeth", "student": "Mary" } -{ "staff": "Elisabeth", "student": "Olga" } -{ "staff": "Elisabeth", "student": "Steve" } -{ "staff": "Elisabeth", "student": "Tess" } -{ "staff": "Franklin", "student": "Karen" } -{ "staff": "Franklin", "student": "Mary" } -{ "staff": "Franklin", "student": "Steve" } -{ "staff": "Franklin", "student": "Tess" } -{ "staff": "Henry", "student": "Charles" } -{ "staff": "Henry", "student": "Frank" } -{ "staff": "Henry", "student": "Karen" } -{ "staff": "Henry", "student": "Mary" } -{ "staff": "Henry", "student": "Steve" } -{ "staff": "Maryann", "student": "Karen" } -{ "staff": "Maryann", "student": "Steve" } -{ "staff": "Maryann", "student": "Tess" } -{ "staff": "Vicky", "student": "Charles" } -{ "staff": "Vicky", "student": "Frank" } -{ "staff": "Vicky", "student": "Karen" } -{ "staff": "Vicky", "student": "Mary" } -{ "staff": "Vicky", "student": "Olga" } -{ "staff": "Vicky", "student": "Steve" } -{ "staff": "Vicky", "student": "Tess" } -{ "staff": "Zack", "student": "Charles" } -{ "staff": "Zack", "student": "Frank" } -{ "staff": "Zack", "student": "Mary" } -{ "staff": "Zack", "student": "Olga" } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isarray/isarray.1.query.sqlpp ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isarray/isarray.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isarray/isarray.1.query.sqlpp new file mode 100644 index 0000000..ab87cb1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isarray/isarray.1.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. + */ + +{ + "a": isarray(true), + "b": isarray(false), + "c": isarray(null), + "d": isarray(missing), + "e": is_array("d"), + "f": is_array(4.0), + "g": isarray(5), + "h": isarray(["1", 2]), + "i": isarray({"a":1}) +}; http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isboolean/isboolean.1.query.sqlpp ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isboolean/isboolean.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isboolean/isboolean.1.query.sqlpp new file mode 100644 index 0000000..de3c64e --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isboolean/isboolean.1.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. + */ + +{ + "a": isboolean(true), + "b": isboolean(false), + "c": is_boolean(null), + "d": is_boolean(missing), + "e": isbool("d"), + "f": isbool(4.0), + "g": isbool(5), + "h": isbool(["1", 2]), + "i": isbool({"a":1}) +}; http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isnumber/isnumber.1.query.sqlpp ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isnumber/isnumber.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isnumber/isnumber.1.query.sqlpp new file mode 100644 index 0000000..1e153d3 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isnumber/isnumber.1.query.sqlpp @@ -0,0 +1,31 @@ +/* + * 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. + */ + +{ + "a": isnumber(true), + "b": isnumber(false), + "c": isnumber(null), + "d": is_number(missing), + "e": is_number("d"), + "f": isnumber(4.0), + "g": isnum(5), + "h": isnum(["1", 2]), + "i": isnum({"a":1}) +}; + http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isobject/isobject.1.query.sqlpp ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isobject/isobject.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isobject/isobject.1.query.sqlpp new file mode 100644 index 0000000..8305977 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isobject/isobject.1.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. + */ + +{ + "a": isobject(true), + "b": isobject(false), + "c": is_object(null), + "d": is_object(missing), + "e": isobj("d"), + "f": isobj(4.0), + "g": isobj(5), + "h": isobj(["1", 2]), + "i": isobj({"a":1}) +}; http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isstring/isstring.1.query.sqlpp ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isstring/isstring.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isstring/isstring.1.query.sqlpp new file mode 100644 index 0000000..a5caf3c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isstring/isstring.1.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. + */ + +{ + "a": is_string(true), + "b": isstring(false), + "c": isstring(null), + "d": isstr(missing), + "e": isstr("d"), + "f": isstr(4.0), + "g": isstr(5), + "h": isstr(["1", 2]), + "i": isstr({"a":1}) +}; http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isarray/isarray.1.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isarray/isarray.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isarray/isarray.1.adm new file mode 100644 index 0000000..b97271c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isarray/isarray.1.adm @@ -0,0 +1 @@ +{ "a": false, "b": false, "c": null, "e": false, "f": false, "g": false, "h": true, "i": false } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isboolean/isboolean.1.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isboolean/isboolean.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isboolean/isboolean.1.adm new file mode 100644 index 0000000..66ed941 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isboolean/isboolean.1.adm @@ -0,0 +1 @@ +{ "a": true, "b": true, "c": null, "e": false, "f": false, "g": false, "h": false, "i": false } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isnumber/isnumber.1.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isnumber/isnumber.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isnumber/isnumber.1.adm new file mode 100644 index 0000000..fc8b4a8 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isnumber/isnumber.1.adm @@ -0,0 +1 @@ +{ "a": false, "b": false, "c": null, "e": false, "f": true, "g": true, "h": false, "i": false } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isobject/isobject.1.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isobject/isobject.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isobject/isobject.1.adm new file mode 100644 index 0000000..00007d7 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isobject/isobject.1.adm @@ -0,0 +1 @@ +{ "a": false, "b": false, "c": null, "e": false, "f": false, "g": false, "h": false, "i": true } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isstring/isstring.1.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isstring/isstring.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isstring/isstring.1.adm new file mode 100644 index 0000000..6a8318f --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isstring/isstring.1.adm @@ -0,0 +1 @@ +{ "a": false, "b": false, "c": null, "e": true, "f": false, "g": false, "h": false, "i": false } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index 38ef4c2..48fa1cd 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -7921,6 +7921,31 @@ </compilation-unit> </test-case> <test-case FilePath="types"> + <compilation-unit name="isarray"> + <output-dir compare="Text">isarray</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="types"> + <compilation-unit name="isboolean"> + <output-dir compare="Text">isboolean</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="types"> + <compilation-unit name="isnumber"> + <output-dir compare="Text">isnumber</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="types"> + <compilation-unit name="isobject"> + <output-dir compare="Text">isobject</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="types"> + <compilation-unit name="isstring"> + <output-dir compare="Text">isstring</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="types"> <compilation-unit name="record01"> <output-dir compare="Text">record01</output-dir> </compilation-unit> http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-doc/pom.xml ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-doc/pom.xml b/asterixdb/asterix-doc/pom.xml index f674f7f..a41bce2 100644 --- a/asterixdb/asterix-doc/pom.xml +++ b/asterixdb/asterix-doc/pom.xml @@ -58,11 +58,11 @@ </concat> <concat destfile="${project.build.directory}/generated-site/markdown/sqlpp/builtins.md"> <filelist dir="${project.basedir}/src/main/markdown/builtins" - files="0_toc.md,1_numeric.md,2_string.md,3_binary.md,4_spatial.md,5_similarity.md,6_tokenizing.md,7_temporal.md,7_allens.md,8_record.md,9_aggregate_sql.md,10_comparison.md,11_others.md"/> + files="0_toc.md,1_numeric.md,2_string.md,3_binary.md,4_spatial.md,5_similarity.md,6_tokenizing.md,7_temporal.md,7_allens.md,8_record.md,9_aggregate_sql.md,10_comparison.md,11_type.md,12_misc.md"/> </concat> <concat destfile="${project.build.directory}/generated-site/markdown/aql/builtins.md"> <filelist dir="${project.basedir}/src/main/markdown/builtins" - files="0_toc.md,1_numeric.md,2_string.md,3_binary.md,4_spatial.md,5_similarity.md,6_tokenizing.md,7_temporal.md,7_allens.md,8_record.md,9_aggregate_aql.md,10_comparison.md,11_others.md"/> + files="0_toc.md,1_numeric.md,2_string.md,3_binary.md,4_spatial.md,5_similarity.md,6_tokenizing.md,7_temporal.md,7_allens.md,8_record.md,9_aggregate_aql.md,10_comparison.md,11_type.md,12_misc.md"/> </concat> </target> </configuration> http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md index 2c8dedf..2cab02c 100644 --- a/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md +++ b/asterixdb/asterix-doc/src/main/markdown/builtins/0_toc.md @@ -31,7 +31,8 @@ * [Record Functions](#RecordFunctions) * [Aggregate Functions (Array Functions)](#AggregateFunctions) * [Comparison Functions](#ComparisonFunctions) -* [Other Functions](#OtherFunctions) +* [Type Functions](#TypeFunctions) +* [Miscellaneous Functions](#MiscFunctions) The system provides various classes of functions to support operations on numeric, string, spatial, and temporal data. This document explains how to use these functions. http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-doc/src/main/markdown/builtins/11_others.md ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/11_others.md b/asterixdb/asterix-doc/src/main/markdown/builtins/11_others.md deleted file mode 100644 index a20b8b3..0000000 --- a/asterixdb/asterix-doc/src/main/markdown/builtins/11_others.md +++ /dev/null @@ -1,249 +0,0 @@ -<!-- - ! 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. - !--> - -## <a id="OtherFunctions">Other Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font> ## - -### uuid ### - * Syntax: - - uuid() - -* Generates a `uuid`. -* Arguments: - * none -* Return Value: - * a generated, random `uuid`. - - -### is_null ### - * Syntax: - - is_null(expr) - - * Checks whether the given expression is evaluated to be a `null` value. - * Arguments: - * `expr` : an expression (any type is allowed). - * Return Value: - * a `boolean` on whether the variable is a `null` or not, - * a `missing` if the input is `missing`. - - * Example: - - { "v1": is_null(null), "v2": is_null(1), "v3": is_null(missing) }; - - - * The expected result is: - - { "v1": true, "v2": false } - - -### is_missing ### - * Syntax: - - is_missing(expr) - - * Checks whether the given expression is evaluated to be a `missing` value. - * Arguments: - * `expr` : an expression (any type is allowed). - * Return Value: - * a `boolean` on whether the variable is a `missing` or not. - - * Example: - - { "v1": is_missing(null), "v2": is_missing(1), "v3": is_missing(missing) }; - - - * The expected result is: - - { "v1": false, "v2": false, "v3": true } - - -### is_unknown ### - * Syntax: - - is_unknown(expr) - - * Checks whether the given variable is a `null` value or a `missing` value. - * Arguments: - * `expr` : an expression (any type is allowed). - * Return Value: - * a `boolean` on whether the variable is a `null`/``missing` value (`true`) or not (`false`). - - * Example: - - { "v1": is_unknown(null), "v2": is_unknown(1), "v3": is_unknown(missing) }; - - - * The expected result is: - - { "v1": true, "v2": false, "v3": true } - - -### len ### - * Syntax: - - len(array) - - * Returns the length of the array array. - * Arguments: - * `array` : an `array`, `multiset`, `null`, or `missing`, represents the collection that needs to be checked. - * Return Value: - * an `integer` that represents the length of input array or the size of the input multiset, - * `missing` if any argument is a `missing` value, - * `null` if any argument is a `null` value but no argument is a `missing` value. - - * Example: - - len(["Hello", "World"]) - - - * The expected result is: - - 2 - - -### not ### - * Syntax: - - not(expr) - - * Inverts a `boolean` value - * Arguments: - * `expr` : an expression - * Return Value: - * a `boolean`, the inverse of `expr`, - * `missing` if any argument is a `missing` value, - * `null` if any argument is a `null` value but no argument is a `missing` value, - * other non-boolean argument value will cause a type error. - * Example: - - { "v1": `not`(true), "v2": `not`(false), "v3": `not`(null), "v4": `not`(missing) }; - - * The expected result is: - - { "v1": false, "v2": true, "v3": null } - - -### range ### - * Syntax: - - range(start_numeric_value, end_numeric_value) - -* Generates a series of `bigint` values based start the `start_numeric_value` until the `end_numeric_value`. -* Arguments: - * `start_numeric_value`: a `tinyint`/`smallint`/`integer`/`bigint` value representing the start value. - * `end_numeric_value`: a `tinyint`/`smallint`/`integer`/`bigint` value representing the max final value. -* Return Value: - * an array that starts with the integer value of `start_numeric_value` and ends with - the integer value of `end_numeric_value`, where the value of each entry in the array is - the integer successor of the value in the preceding entry. -* Example: - - range(0, 3); - - * The expected result is: - - [ 0, 1, 2, 3 ] - - -### switch_case ### - * Syntax: - - switch_case( - condition, - case1, case1_result, - case2, case2_result, - ..., - default, default_result - ) - - * Switches amongst a sequence of cases and returns the result of the first matching case. If no match is found, the result of the default case is returned. - * Arguments: - * `condition`: a variable (any type is allowed). - * `caseI/default`: a variable (any type is allowed). - * `caseI/default_result`: a variable (any type is allowed). - * Return Value: - * `caseI_result` if `condition` matches `caseI`, otherwise `default_result`. - * Example 1: - - switch_case( - "a", - "a", 0, - "x", 1, - "y", 2, - "z", 3 - ); - - - * The expected result is: - - 0 - - * Example 2: - - switch_case( - "a", - "x", 1, - "y", 2, - "z", 3 - ); - - * The expected result is: - - 3 - - -### deep_equal ### -* Syntax: - - deep_equal(expr1, expr2) - - - * Assess the equality between two expressions of any type (e.g., record, arrays, or multiset). - Two objects are deeply equal iff both their types and values are equal. - * Arguments: - * `expr1` : an expression, - * `expr2` : an expression. - * Return Value: - * `true` or `false` depending on the data equality, - * `missing` if any argument is a `missing` value, - * `null` if any argument is a `null` value but no argument is a `missing` value. - - - * Example: - - deep_equal( - { - "id":1, - "project":"AsterixDB", - "address":{"city":"Irvine", "state":"CA"}, - "related":["Hivestrix", "Preglix", "Apache VXQuery"] - }, - { - "id":1, - "project":"AsterixDB", - "address":{"city":"San Diego", "state":"CA"}, - "related":["Hivestrix", "Preglix", "Apache VXQuery"] - } - ); - - * The expected result is: - - false - http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-doc/src/main/markdown/builtins/11_type.md ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/11_type.md b/asterixdb/asterix-doc/src/main/markdown/builtins/11_type.md new file mode 100644 index 0000000..7d355b2 --- /dev/null +++ b/asterixdb/asterix-doc/src/main/markdown/builtins/11_type.md @@ -0,0 +1,263 @@ +<!-- + ! 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. + !--> + +## <a id="TypeFunctions">Type Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font> ## + +### is_array (isarray) ### + * Syntax: + + is_array(expr) + + * Checks whether the given expression is evaluated to be an `array` value. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the argument is an `array` value or not, + * a `missing` if the argument is a `missing` value, + * a `null` if the argument is a `null` value. + + * Example: + + { + "a": is_array(true), + "b": is_array(false), + "c": isarray(null), + "d": isarray(missing), + "e": isarray("d"), + "f": isarray(4.0), + "g": isarray(5), + "h": isarray(["1", 2]), + "i": isarray({"a":1}) + }; + + + * The expected result is: + + { "a": false, "b": false, "c": null, "e": false, "f": false, "g": false, "h": true, "i": false } + + The function has an alias `isarray`. + + +### is_boolean (isboolean, isbool) ### + * Syntax: + + is_boolean(expr) + + * Checks whether the given expression is evaluated to be a `boolean` value. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the argument is a `boolean` value or not, + * a `missing` if the argument is a `missing` value, + * a `null` if the argument is a `null` value. + + * Example: + + { + "a": isboolean(true), + "b": isboolean(false), + "c": is_boolean(null), + "d": is_boolean(missing), + "e": isbool("d"), + "f": isbool(4.0), + "g": isbool(5), + "h": isbool(["1", 2]), + "i": isbool({"a":1}) + }; + + + * The expected result is: + + { "a": true, "b": true, "c": null, "e": false, "f": false, "g": false, "h": false, "i": false } + + The function has two aliases, `isboolean` or `isbool`. + + +### is_number (isnumber, isnum) ### + * Syntax: + + is_number(expr) + + * Checks whether the given expression is evaluated to be a numeric value. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the argument is a `smallint`/`tinyint`/`integer`/`bigint`/`float`/`double` + value or not, + * a `missing` if the argument is a `missing` value, + * a `null` if the argument is a `null` value. + + * Example: + + { + "a": is_number(true), + "b": is_number(false), + "c": isnumber(null), + "d": isnumber(missing), + "e": isnumber("d"), + "f": isnum(4.0), + "g": isnum(5), + "h": isnum(["1", 2]), + "i": isnum({"a":1}) + }; + + + * The expected result is: + + { "a": false, "b": false, "c": null, "e": false, "f": true, "g": true, "h": false, "i": false } + + The function has two aliases, `isnumber` or `isnum`. + +### is_object (isobject, isobj) ### + * Syntax: + + is_object(expr) + + * Checks whether the given expression is evaluated to be a `record` value. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the argument is a `record` value or not, + * a `missing` if the argument is a `missing` value, + * a `null` if the argument is a `null` value. + + * Example: + + { + "a": is_object(true), + "b": is_object(false), + "c": isobject(null), + "d": isobject(missing), + "e": isobj("d"), + "f": isobj(4.0), + "g": isobj(5), + "h": isobj(["1", 2]), + "i": isobj({"a":1}) + }; + + + * The expected result is: + + { "a": false, "b": false, "c": null, "e": false, "f": false, "g": false, "h": false, "i": true } + + The function has two aliases, `isobject` or `isobj`. + + +### is_string (isstring, isstr) ### + * Syntax: + + is_string(expr) + + * Checks whether the given expression is evaluated to be a `string` value. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the argument is a `string` value or not, + * a `missing` if the argument is a `missing` value, + * a `null` if the argument is a `null` value. + + * Example: + + { + "a": is_string(true), + "b": isstring(false), + "c": isstring(null), + "d": isstr(missing), + "e": isstr("d"), + "f": isstr(4.0), + "g": isstr(5), + "h": isstr(["1", 2]), + "i": isstr({"a":1}) + }; + + + * The expected result is: + + { "a": false, "b": false, "c": null, "e": true, "f": false, "g": false, "h": false, "i": false } + + The function has two aliases, `isstring` or `isstr`. + + +### is_null ### + * Syntax: + + is_null(expr) + + * Checks whether the given expression is evaluated to be a `null` value. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the variable is a `null` or not, + * a `missing` if the input is `missing`. + + * Example: + + { "v1": is_null(null), "v2": is_null(1), "v3": is_null(missing) }; + + + * The expected result is: + + { "v1": true, "v2": false } + + The function has an alias `isnull`. + +### is_missing ### + * Syntax: + + is_missing(expr) + + * Checks whether the given expression is evaluated to be a `missing` value. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the variable is a `missing` or not. + + * Example: + + { "v1": is_missing(null), "v2": is_missing(1), "v3": is_missing(missing) }; + + + * The expected result is: + + { "v1": false, "v2": false, "v3": true } + + The function has an alias `ismissing`. + +### is_unknown ### + * Syntax: + + is_unknown(expr) + + * Checks whether the given variable is a `null` value or a `missing` value. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the variable is a `null`/``missing` value (`true`) or not (`false`). + + * Example: + + { "v1": is_unknown(null), "v2": is_unknown(1), "v3": is_unknown(missing) }; + + + * The expected result is: + + { "v1": true, "v2": false, "v3": true } + + The function has an alias `isunknown`. + http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-doc/src/main/markdown/builtins/12_misc.md ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/12_misc.md b/asterixdb/asterix-doc/src/main/markdown/builtins/12_misc.md new file mode 100644 index 0000000..ee5ca31 --- /dev/null +++ b/asterixdb/asterix-doc/src/main/markdown/builtins/12_misc.md @@ -0,0 +1,185 @@ +<!-- + ! 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. + !--> + +## <a id="MiscFunctions">Miscellaneous Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font> ## + +### uuid ### + * Syntax: + + uuid() + +* Generates a `uuid`. +* Arguments: + * none +* Return Value: + * a generated, random `uuid`. + + +### len ### + * Syntax: + + len(array) + + * Returns the length of the array array. + * Arguments: + * `array` : an `array`, `multiset`, `null`, or `missing`, represents the collection that needs to be checked. + * Return Value: + * an `integer` that represents the length of input array or the size of the input multiset, + * `missing` if any argument is a `missing` value, + * `null` if any argument is a `null` value but no argument is a `missing` value. + + * Example: + + len(["Hello", "World"]) + + + * The expected result is: + + 2 + + +### not ### + * Syntax: + + not(expr) + + * Inverts a `boolean` value + * Arguments: + * `expr` : an expression + * Return Value: + * a `boolean`, the inverse of `expr`, + * `missing` if any argument is a `missing` value, + * `null` if any argument is a `null` value but no argument is a `missing` value, + * other non-boolean argument value will cause a type error. + * Example: + + { "v1": `not`(true), "v2": `not`(false), "v3": `not`(null), "v4": `not`(missing) }; + + * The expected result is: + + { "v1": false, "v2": true, "v3": null } + + +### range ### + * Syntax: + + range(start_numeric_value, end_numeric_value) + +* Generates a series of `bigint` values based start the `start_numeric_value` until the `end_numeric_value`. +* Arguments: + * `start_numeric_value`: a `tinyint`/`smallint`/`integer`/`bigint` value representing the start value. + * `end_numeric_value`: a `tinyint`/`smallint`/`integer`/`bigint` value representing the max final value. +* Return Value: + * an array that starts with the integer value of `start_numeric_value` and ends with + the integer value of `end_numeric_value`, where the value of each entry in the array is + the integer successor of the value in the preceding entry. +* Example: + + range(0, 3); + + * The expected result is: + + [ 0, 1, 2, 3 ] + + +### switch_case ### + * Syntax: + + switch_case( + condition, + case1, case1_result, + case2, case2_result, + ..., + default, default_result + ) + + * Switches amongst a sequence of cases and returns the result of the first matching case. If no match is found, the result of the default case is returned. + * Arguments: + * `condition`: a variable (any type is allowed). + * `caseI/default`: a variable (any type is allowed). + * `caseI/default_result`: a variable (any type is allowed). + * Return Value: + * `caseI_result` if `condition` matches `caseI`, otherwise `default_result`. + * Example 1: + + switch_case( + "a", + "a", 0, + "x", 1, + "y", 2, + "z", 3 + ); + + + * The expected result is: + + 0 + + * Example 2: + + switch_case( + "a", + "x", 1, + "y", 2, + "z", 3 + ); + + * The expected result is: + + 3 + + +### deep_equal ### +* Syntax: + + deep_equal(expr1, expr2) + + + * Assess the equality between two expressions of any type (e.g., record, arrays, or multiset). + Two objects are deeply equal iff both their types and values are equal. + * Arguments: + * `expr1` : an expression, + * `expr2` : an expression. + * Return Value: + * `true` or `false` depending on the data equality, + * `missing` if any argument is a `missing` value, + * `null` if any argument is a `null` value but no argument is a `missing` value. + + + * Example: + + deep_equal( + { + "id":1, + "project":"AsterixDB", + "address":{"city":"Irvine", "state":"CA"}, + "related":["Hivestrix", "Preglix", "Apache VXQuery"] + }, + { + "id":1, + "project":"AsterixDB", + "address":{"city":"San Diego", "state":"CA"}, + "related":["Hivestrix", "Preglix", "Apache VXQuery"] + } + ); + + * The expected result is: + + false + http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java index 1f7e4b0..6e7349e 100644 --- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java +++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java @@ -48,6 +48,20 @@ public class CommonFunctionMapUtil { FUNCTION_NAME_MAP.put("smallint", "int16"); // smallint, internal: int16 FUNCTION_NAME_MAP.put("integer", "int32"); // integer, internal: int32 FUNCTION_NAME_MAP.put("bigint", "int64"); // bigint, internal: int64 + + // Type functions. + FUNCTION_NAME_MAP.put("isnull", "is-null"); // isnull, internal: is-null + FUNCTION_NAME_MAP.put("ismissing", "is-missing"); // ismissing, internal: is-missing + FUNCTION_NAME_MAP.put("isunknown", "is-unknown"); // isunknown, internal: is-unknown + FUNCTION_NAME_MAP.put("isboolean", "is-boolean"); // isboolean, internal: is-boolean + FUNCTION_NAME_MAP.put("isbool", "is-boolean"); // isbool, internal: is-boolean + FUNCTION_NAME_MAP.put("isnumber", "is-number"); // isnumber, internal: is-number + FUNCTION_NAME_MAP.put("isnum", "is-number"); // isnum, internal: is-number + FUNCTION_NAME_MAP.put("isstring", "is-string"); // isstring, internal: is-string + FUNCTION_NAME_MAP.put("isstr", "is-string"); // isstr, internal: is-string + FUNCTION_NAME_MAP.put("isarray", "is-array"); // isarray, internal: is-array + FUNCTION_NAME_MAP.put("isobject", "is-object"); // isobject, internal: is-object + FUNCTION_NAME_MAP.put("isobj", "is-object"); // isobj, internal: is-object } private CommonFunctionMapUtil() { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java index a85d33b..80f13d6 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java @@ -761,6 +761,16 @@ public class AsterixBuiltinFunctions { public static final FunctionIdentifier IS_NULL = AlgebricksBuiltinFunctions.IS_NULL; public static final FunctionIdentifier IS_UNKOWN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-unknown", 1); + public static final FunctionIdentifier IS_BOOLEAN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, + "is-boolean", 1); + public static final FunctionIdentifier IS_NUMBER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-number", + 1); + public static final FunctionIdentifier IS_STRING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-string", + 1); + public static final FunctionIdentifier IS_ARRAY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-array", + 1); + public static final FunctionIdentifier IS_OBJECT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-object", + 1); public static final FunctionIdentifier IS_SYSTEM_NULL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-system-null", 1); @@ -794,6 +804,11 @@ public class AsterixBuiltinFunctions { addFunction(IS_NULL, BooleanOnlyTypeComputer.INSTANCE, true); addFunction(IS_UNKOWN, BooleanOnlyTypeComputer.INSTANCE, true); addFunction(IS_SYSTEM_NULL, BooleanOnlyTypeComputer.INSTANCE, true); + addFunction(IS_BOOLEAN, BooleanOnlyTypeComputer.INSTANCE, true); + addFunction(IS_NUMBER, BooleanOnlyTypeComputer.INSTANCE, true); + addFunction(IS_STRING, BooleanOnlyTypeComputer.INSTANCE, true); + addFunction(IS_ARRAY, BooleanOnlyTypeComputer.INSTANCE, true); + addFunction(IS_OBJECT, BooleanOnlyTypeComputer.INSTANCE, true); addFunction(NOT, BooleanFunctionTypeComputer.INSTANCE, true); addPrivateFunction(EQ, BooleanFunctionTypeComputer.INSTANCE, true); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsArrayDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsArrayDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsArrayDescriptor.java new file mode 100644 index 0000000..c8cb313 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsArrayDescriptor.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +package org.apache.asterix.runtime.evaluators.functions; + +import org.apache.asterix.om.functions.AsterixBuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +import org.apache.asterix.runtime.evaluators.common.AbstractTypeCheckEvaluator; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; + +public class IsArrayDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new IsArrayDescriptor(); + } + }; + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) + throws AlgebricksException { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { + final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx); + return new AbstractTypeCheckEvaluator(eval) { + + @Override + protected Value isMatch(byte typeTag) { + return typeTag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG ? Value.TRUE : Value.FALSE; + } + }; + } + }; + } + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.IS_ARRAY; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsBooleanDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsBooleanDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsBooleanDescriptor.java new file mode 100644 index 0000000..89318bd --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsBooleanDescriptor.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +package org.apache.asterix.runtime.evaluators.functions; + +import org.apache.asterix.om.functions.AsterixBuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +import org.apache.asterix.runtime.evaluators.common.AbstractTypeCheckEvaluator; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; + +public class IsBooleanDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new IsBooleanDescriptor(); + } + }; + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) + throws AlgebricksException { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { + final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx); + return new AbstractTypeCheckEvaluator(eval) { + + @Override + protected Value isMatch(byte typeTag) { + return typeTag == ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG ? Value.TRUE : Value.FALSE; + } + }; + } + }; + } + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.IS_BOOLEAN; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNumberDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNumberDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNumberDescriptor.java new file mode 100644 index 0000000..418d778 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNumberDescriptor.java @@ -0,0 +1,73 @@ +/* + * 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. + */ + +package org.apache.asterix.runtime.evaluators.functions; + +import org.apache.asterix.om.functions.AsterixBuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +import org.apache.asterix.runtime.evaluators.common.AbstractTypeCheckEvaluator; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; + +public class IsNumberDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new IsNumberDescriptor(); + } + }; + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) + throws AlgebricksException { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { + final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx); + return new AbstractTypeCheckEvaluator(eval) { + + @Override + protected Value isMatch(byte typeTag) { + return typeTag == ATypeTag.SERIALIZED_INT8_TYPE_TAG + || typeTag == ATypeTag.SERIALIZED_INT16_TYPE_TAG + || typeTag == ATypeTag.SERIALIZED_INT32_TYPE_TAG + || typeTag == ATypeTag.SERIALIZED_INT64_TYPE_TAG + || typeTag == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG + || typeTag == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG ? Value.TRUE : Value.FALSE; + } + }; + } + }; + } + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.IS_NUMBER; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsObjectDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsObjectDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsObjectDescriptor.java new file mode 100644 index 0000000..5a3f2d3 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsObjectDescriptor.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +package org.apache.asterix.runtime.evaluators.functions; + +import org.apache.asterix.om.functions.AsterixBuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +import org.apache.asterix.runtime.evaluators.common.AbstractTypeCheckEvaluator; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; + +public class IsObjectDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new IsObjectDescriptor(); + } + }; + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) + throws AlgebricksException { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { + final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx); + return new AbstractTypeCheckEvaluator(eval) { + + @Override + protected Value isMatch(byte typeTag) { + return typeTag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG ? Value.TRUE : Value.FALSE; + } + }; + } + }; + } + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.IS_OBJECT; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8fa8b7af/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsStringDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsStringDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsStringDescriptor.java new file mode 100644 index 0000000..44c5a6c --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsStringDescriptor.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +package org.apache.asterix.runtime.evaluators.functions; + +import org.apache.asterix.om.functions.AsterixBuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +import org.apache.asterix.runtime.evaluators.common.AbstractTypeCheckEvaluator; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; + +public class IsStringDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new IsStringDescriptor(); + } + }; + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) + throws AlgebricksException { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { + final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx); + return new AbstractTypeCheckEvaluator(eval) { + + @Override + protected Value isMatch(byte typeTag) { + return typeTag == ATypeTag.SERIALIZED_STRING_TYPE_TAG ? Value.TRUE : Value.FALSE; + } + }; + } + }; + } + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.IS_STRING; + } + +}