Dmitry Lychagin has submitted this change and it was merged. Change subject: [ASTERIXDB-2371][FUN] Implement conditional functions ......................................................................
[ASTERIXDB-2371][FUN] Implement conditional functions - user model changes: yes - storage format changes: no - interface changes: no Details: - Implement the following conditional functions: null_if(), missing_if(), nan_if(), posinf_if(), neginf_if() Change-Id: I5399cae1a225b1881d67b87541e46a9d4fe158ec Reviewed-on: https://asterix-gerrit.ics.uci.edu/2616 Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Till Westmann <ti...@apache.org> --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/missingif/missingif.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/missingif/missingif.2.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nanif/nanif.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nanif/nanif.2.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/neginfif/neginfif.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/neginfif/neginfif.2.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nullif/nullif.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nullif/nullif.2.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/posinfif/posinfif.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/posinfif/posinfif.2.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/missingif/missingif.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/missingif/missingif.2.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nanif/nanif.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nanif/nanif.2.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/neginfif/neginfif.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/neginfif/neginfif.2.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nullif/nullif.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nullif/nullif.2.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/posinfif/posinfif.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/posinfif/posinfif.2.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java A asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/DoubleIfTypeComputer.java A asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MissingIfTypeComputer.java A asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NullIfTypeComputer.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractIfEqualsEvaluator.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractValueComparisonEvaluator.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/EqualsDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanOrEqualsDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanOrEqualsDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/MissingIfEqualsDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NanIfEqualsDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NegInfIfEqualsDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NotEqualsDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NullIfEqualsDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/PosInfIfEqualsDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java 42 files changed, 1,317 insertions(+), 88 deletions(-) Approvals: Anon. E. Moose #1000171: Till Westmann: Looks good to me, approved Jenkins: Verified; No violations found; ; Verified diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/missingif/missingif.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/missingif/missingif.1.query.sqlpp new file mode 100644 index 0000000..c11dd76 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/missingif/missingif.1.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "t1": missingif(missing, missing) is missing, + "t2": missingif(missing, 2) is missing, + "t3": missingif(2, missing) is missing, + "t4": missingif(missing, null) is missing, + "t5": missingif(null, missing) is missing, + "t6": missingif(null, null) is null, + "t7": missingif(null, 2) is null, + "t8": missingif(2, null) is null +} \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/missingif/missingif.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/missingif/missingif.2.query.sqlpp new file mode 100644 index 0000000..b5f08ec --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/missingif/missingif.2.query.sqlpp @@ -0,0 +1,24 @@ +/* + * 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 + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t1, + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t2 +select value [ t1[1], t2[1], if_missing(missing_if(t1[1], t2[1]), "MISSING") ] +order by t1[0], t2[0] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nanif/nanif.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nanif/nanif.1.query.sqlpp new file mode 100644 index 0000000..44e64d0 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nanif/nanif.1.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "t1": nanif(missing, missing) is missing, + "t2": nanif(missing, 2) is missing, + "t3": nanif(2, missing) is missing, + "t4": nanif(missing, null) is missing, + "t5": nanif(null, missing) is missing, + "t6": nanif(null, null) is null, + "t7": nanif(null, 2) is null, + "t8": nanif(2, null) is null +} \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nanif/nanif.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nanif/nanif.2.query.sqlpp new file mode 100644 index 0000000..05e003e --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nanif/nanif.2.query.sqlpp @@ -0,0 +1,24 @@ +/* + * 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 + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t1, + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t2 +select value [ t1[1], t2[1], to_string(nan_if(t1[1], t2[1])) ] +order by t1[0], t2[0] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/neginfif/neginfif.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/neginfif/neginfif.1.query.sqlpp new file mode 100644 index 0000000..abd4a4b --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/neginfif/neginfif.1.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "t1": neginfif(missing, missing) is missing, + "t2": neginfif(missing, 2) is missing, + "t3": neginfif(2, missing) is missing, + "t4": neginfif(missing, null) is missing, + "t5": neginfif(null, missing) is missing, + "t6": neginfif(null, null) is null, + "t7": neginfif(null, 2) is null, + "t8": neginfif(2, null) is null +} \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/neginfif/neginfif.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/neginfif/neginfif.2.query.sqlpp new file mode 100644 index 0000000..67dcd34 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/neginfif/neginfif.2.query.sqlpp @@ -0,0 +1,24 @@ +/* + * 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 + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t1, + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t2 +select value [ t1[1], t2[1], to_string(neginf_if(t1[1], t2[1])) ] +order by t1[0], t2[0] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nullif/nullif.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nullif/nullif.1.query.sqlpp new file mode 100644 index 0000000..69ef8e1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nullif/nullif.1.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "t1": nullif(missing, missing) is missing, + "t2": nullif(missing, 2) is missing, + "t3": nullif(2, missing) is missing, + "t4": nullif(missing, null) is missing, + "t5": nullif(null, missing) is missing, + "t6": nullif(null, null) is null, + "t7": nullif(null, 2) is null, + "t8": nullif(2, null) is null +} \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nullif/nullif.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nullif/nullif.2.query.sqlpp new file mode 100644 index 0000000..d5d6be3 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/nullif/nullif.2.query.sqlpp @@ -0,0 +1,24 @@ +/* + * 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 + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t1, + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t2 +select value [ t1[1], t2[1], if_null(null_if(t1[1], t2[1]), "NULL") ] +order by t1[0], t2[0] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/posinfif/posinfif.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/posinfif/posinfif.1.query.sqlpp new file mode 100644 index 0000000..399f4d4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/posinfif/posinfif.1.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "t1": posinfif(missing, missing) is missing, + "t2": posinfif(missing, 2) is missing, + "t3": posinfif(2, missing) is missing, + "t4": posinfif(missing, null) is missing, + "t5": posinfif(null, missing) is missing, + "t6": posinfif(null, null) is null, + "t7": posinfif(null, 2) is null, + "t8": posinfif(2, null) is null +} \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/posinfif/posinfif.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/posinfif/posinfif.2.query.sqlpp new file mode 100644 index 0000000..cf25c1c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/posinfif/posinfif.2.query.sqlpp @@ -0,0 +1,24 @@ +/* + * 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 + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t1, + [ [0, true], [1, false], [2,2], [3,3], [4,"abc"], [5,"def"] ] t2 +select value [ t1[1], t2[1], to_string(posinf_if(t1[1], t2[1])) ] +order by t1[0], t2[0] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/missingif/missingif.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/missingif/missingif.1.adm new file mode 100644 index 0000000..b0a2b5a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/missingif/missingif.1.adm @@ -0,0 +1 @@ +{ "t1": true, "t2": true, "t3": true, "t4": true, "t5": true, "t6": true, "t7": true, "t8": true } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/missingif/missingif.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/missingif/missingif.2.adm new file mode 100644 index 0000000..fca4cbf --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/missingif/missingif.2.adm @@ -0,0 +1,36 @@ +[ true, true, "MISSING" ] +[ true, false, true ] +[ true, 2, true ] +[ true, 3, true ] +[ true, "abc", true ] +[ true, "def", true ] +[ false, true, false ] +[ false, false, "MISSING" ] +[ false, 2, false ] +[ false, 3, false ] +[ false, "abc", false ] +[ false, "def", false ] +[ 2, true, 2 ] +[ 2, false, 2 ] +[ 2, 2, "MISSING" ] +[ 2, 3, 2 ] +[ 2, "abc", 2 ] +[ 2, "def", 2 ] +[ 3, true, 3 ] +[ 3, false, 3 ] +[ 3, 2, 3 ] +[ 3, 3, "MISSING" ] +[ 3, "abc", 3 ] +[ 3, "def", 3 ] +[ "abc", true, "abc" ] +[ "abc", false, "abc" ] +[ "abc", 2, "abc" ] +[ "abc", 3, "abc" ] +[ "abc", "abc", "MISSING" ] +[ "abc", "def", "abc" ] +[ "def", true, "def" ] +[ "def", false, "def" ] +[ "def", 2, "def" ] +[ "def", 3, "def" ] +[ "def", "abc", "def" ] +[ "def", "def", "MISSING" ] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nanif/nanif.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nanif/nanif.1.adm new file mode 100644 index 0000000..b0a2b5a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nanif/nanif.1.adm @@ -0,0 +1 @@ +{ "t1": true, "t2": true, "t3": true, "t4": true, "t5": true, "t6": true, "t7": true, "t8": true } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nanif/nanif.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nanif/nanif.2.adm new file mode 100644 index 0000000..cfcc525 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nanif/nanif.2.adm @@ -0,0 +1,36 @@ +[ true, true, "NaN" ] +[ true, false, "true" ] +[ true, 2, "true" ] +[ true, 3, "true" ] +[ true, "abc", "true" ] +[ true, "def", "true" ] +[ false, true, "false" ] +[ false, false, "NaN" ] +[ false, 2, "false" ] +[ false, 3, "false" ] +[ false, "abc", "false" ] +[ false, "def", "false" ] +[ 2, true, "2" ] +[ 2, false, "2" ] +[ 2, 2, "NaN" ] +[ 2, 3, "2" ] +[ 2, "abc", "2" ] +[ 2, "def", "2" ] +[ 3, true, "3" ] +[ 3, false, "3" ] +[ 3, 2, "3" ] +[ 3, 3, "NaN" ] +[ 3, "abc", "3" ] +[ 3, "def", "3" ] +[ "abc", true, "abc" ] +[ "abc", false, "abc" ] +[ "abc", 2, "abc" ] +[ "abc", 3, "abc" ] +[ "abc", "abc", "NaN" ] +[ "abc", "def", "abc" ] +[ "def", true, "def" ] +[ "def", false, "def" ] +[ "def", 2, "def" ] +[ "def", 3, "def" ] +[ "def", "abc", "def" ] +[ "def", "def", "NaN" ] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/neginfif/neginfif.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/neginfif/neginfif.1.adm new file mode 100644 index 0000000..b0a2b5a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/neginfif/neginfif.1.adm @@ -0,0 +1 @@ +{ "t1": true, "t2": true, "t3": true, "t4": true, "t5": true, "t6": true, "t7": true, "t8": true } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/neginfif/neginfif.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/neginfif/neginfif.2.adm new file mode 100644 index 0000000..1b75b97 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/neginfif/neginfif.2.adm @@ -0,0 +1,36 @@ +[ true, true, "-INF" ] +[ true, false, "true" ] +[ true, 2, "true" ] +[ true, 3, "true" ] +[ true, "abc", "true" ] +[ true, "def", "true" ] +[ false, true, "false" ] +[ false, false, "-INF" ] +[ false, 2, "false" ] +[ false, 3, "false" ] +[ false, "abc", "false" ] +[ false, "def", "false" ] +[ 2, true, "2" ] +[ 2, false, "2" ] +[ 2, 2, "-INF" ] +[ 2, 3, "2" ] +[ 2, "abc", "2" ] +[ 2, "def", "2" ] +[ 3, true, "3" ] +[ 3, false, "3" ] +[ 3, 2, "3" ] +[ 3, 3, "-INF" ] +[ 3, "abc", "3" ] +[ 3, "def", "3" ] +[ "abc", true, "abc" ] +[ "abc", false, "abc" ] +[ "abc", 2, "abc" ] +[ "abc", 3, "abc" ] +[ "abc", "abc", "-INF" ] +[ "abc", "def", "abc" ] +[ "def", true, "def" ] +[ "def", false, "def" ] +[ "def", 2, "def" ] +[ "def", 3, "def" ] +[ "def", "abc", "def" ] +[ "def", "def", "-INF" ] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nullif/nullif.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nullif/nullif.1.adm new file mode 100644 index 0000000..b0a2b5a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nullif/nullif.1.adm @@ -0,0 +1 @@ +{ "t1": true, "t2": true, "t3": true, "t4": true, "t5": true, "t6": true, "t7": true, "t8": true } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nullif/nullif.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nullif/nullif.2.adm new file mode 100644 index 0000000..5c53877 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/nullif/nullif.2.adm @@ -0,0 +1,36 @@ +[ true, true, "NULL" ] +[ true, false, true ] +[ true, 2, true ] +[ true, 3, true ] +[ true, "abc", true ] +[ true, "def", true ] +[ false, true, false ] +[ false, false, "NULL" ] +[ false, 2, false ] +[ false, 3, false ] +[ false, "abc", false ] +[ false, "def", false ] +[ 2, true, 2 ] +[ 2, false, 2 ] +[ 2, 2, "NULL" ] +[ 2, 3, 2 ] +[ 2, "abc", 2 ] +[ 2, "def", 2 ] +[ 3, true, 3 ] +[ 3, false, 3 ] +[ 3, 2, 3 ] +[ 3, 3, "NULL" ] +[ 3, "abc", 3 ] +[ 3, "def", 3 ] +[ "abc", true, "abc" ] +[ "abc", false, "abc" ] +[ "abc", 2, "abc" ] +[ "abc", 3, "abc" ] +[ "abc", "abc", "NULL" ] +[ "abc", "def", "abc" ] +[ "def", true, "def" ] +[ "def", false, "def" ] +[ "def", 2, "def" ] +[ "def", 3, "def" ] +[ "def", "abc", "def" ] +[ "def", "def", "NULL" ] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/posinfif/posinfif.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/posinfif/posinfif.1.adm new file mode 100644 index 0000000..b0a2b5a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/posinfif/posinfif.1.adm @@ -0,0 +1 @@ +{ "t1": true, "t2": true, "t3": true, "t4": true, "t5": true, "t6": true, "t7": true, "t8": true } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/posinfif/posinfif.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/posinfif/posinfif.2.adm new file mode 100644 index 0000000..ebc67b3 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/posinfif/posinfif.2.adm @@ -0,0 +1,36 @@ +[ true, true, "INF" ] +[ true, false, "true" ] +[ true, 2, "true" ] +[ true, 3, "true" ] +[ true, "abc", "true" ] +[ true, "def", "true" ] +[ false, true, "false" ] +[ false, false, "INF" ] +[ false, 2, "false" ] +[ false, 3, "false" ] +[ false, "abc", "false" ] +[ false, "def", "false" ] +[ 2, true, "2" ] +[ 2, false, "2" ] +[ 2, 2, "INF" ] +[ 2, 3, "2" ] +[ 2, "abc", "2" ] +[ 2, "def", "2" ] +[ 3, true, "3" ] +[ 3, false, "3" ] +[ 3, 2, "3" ] +[ 3, 3, "INF" ] +[ 3, "abc", "3" ] +[ 3, "def", "3" ] +[ "abc", true, "abc" ] +[ "abc", false, "abc" ] +[ "abc", 2, "abc" ] +[ "abc", 3, "abc" ] +[ "abc", "abc", "INF" ] +[ "abc", "def", "abc" ] +[ "def", true, "def" ] +[ "def", false, "def" ] +[ "def", 2, "def" ] +[ "def", 3, "def" ] +[ "def", "abc", "def" ] +[ "def", "def", "INF" ] 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 270d81a..6118d29 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -1264,6 +1264,32 @@ <output-dir compare="Text">least_mixed</output-dir> </compilation-unit> </test-case> + <test-case FilePath="comparison"> + <compilation-unit name="missingif"> + <output-dir compare="Text">missingif</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="comparison"> + <compilation-unit name="nullif"> + <output-dir compare="Text">nullif</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="comparison"> + <compilation-unit name="nanif"> + <output-dir compare="Text">nanif</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="comparison"> + <compilation-unit name="posinfif"> + <output-dir compare="Text">posinfif</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="comparison"> + <compilation-unit name="neginfif"> + <output-dir compare="Text">neginfif</output-dir> + </compilation-unit> + </test-case> + </test-group> <test-group name="constructor"> <test-case FilePath="constructor"> diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md b/asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md index ed9551e..f0e98fd 100644 --- a/asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md +++ b/asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md @@ -199,3 +199,150 @@ { "a": true, "b": true, "c": true, "d": 1, "e": true, "f": true, "g": 1 } The function has an alias `ifnanorinf`. + + +### null_if (nullif) ### + + * Syntax: + + null_if(expression1, expression2) + + * Compares two arguments and returns `null` if they are equal, otherwise returns the first argument. + * Arguments: + * `expressionI` : an expression (any type is allowed). + * Return Value: + * `missing` if any argument is a `missing` value, + * `null` if + * any argument is a `null` value but no argument is a `missing` value, or + * `argument1` = `argument2` + * a value of the first argument otherwise + + * Example: + + { + "a": null_if("asterixdb", "asterixdb"), + "b": null_if(1, 2) + }; + + * The expected result is: + + { "a": null, "b": 1 } + + The function has an alias `nullif`. + + +### missing_if (missingif) ### + + * Syntax: + + missing_if(expression1, expression2) + + * Compares two arguments and returns `missing` if they are equal, otherwise returns the first argument. + * Arguments: + * `expressionI` : an expression (any type is allowed). + * Return Value: + * `missing` if + * any argument is a `missing` value, or + * no argument is a `null` value and `argument1` = `argument2` + * `null` if any argument is a `null` value but no argument is a `missing` value + * a value of the first argument otherwise + + * Example: + + { + "a": missing_if("asterixdb", "asterixdb") + "b": missing_if(1, 2), + }; + + * The expected result is: + + { "b": 1 } + + The function has an alias `missingif`. + + +### nan_if (nanif) ### + + * Syntax: + + nan_if(expression1, expression2) + + * Compares two arguments and returns `NaN` value if they are equal, otherwise returns the first argument. + * Arguments: + * `expressionI` : an expression (any type is allowed). + * Return Value: + * `missing` if any argument is a `missing` value, + * `null` if any argument is a `null` value but no argument is a `missing` value + * `NaN` value of type `double` if `argument1` = `argument2` + * a value of the first argument otherwise + + * Example: + + { + "a": to_string(nan_if("asterixdb", "asterixdb")), + "b": nan_if(1, 2) + }; + + * The expected result is: + + { "a": "NaN", "b": 1 } + + The function has an alias `nanif`. + + +### posinf_if (posinfif) ### + + * Syntax: + + posinf_if(expression1, expression2) + + * Compares two arguments and returns `+INF` value if they are equal, otherwise returns the first argument. + * Arguments: + * `expressionI` : an expression (any type is allowed). + * Return Value: + * `missing` if any argument is a `missing` value, + * `null` if any argument is a `null` value but no argument is a `missing` value + * `+INF` value of type `double` if `argument1` = `argument2` + * a value of the first argument otherwise + + * Example: + + { + "a": to_string(posinf_if("asterixdb", "asterixdb")), + "b": posinf_if(1, 2) + }; + + * The expected result is: + + { "a": "+INF", "b": 1 } + + The function has an alias `posinfif`. + + +### neginf_if (neginfif) ### + + * Syntax: + + neginf_if(expression1, expression2) + + * Compares two arguments and returns `-INF` value if they are equal, otherwise returns the first argument. + * Arguments: + * `expressionI` : an expression (any type is allowed). + * Return Value: + * `missing` if any argument is a `missing` value, + * `null` if any argument is a `null` value but no argument is a `missing` value + * `-INF` value of type `double` if `argument1` = `argument2` + * a value of the first argument otherwise + + * Example: + + { + "a": to_string(neginf_if("asterixdb", "asterixdb")), + "b": neginf_if(1, 2) + }; + + * The expected result is: + + { "a": "-INF", "b": 1 } + + The function has an alias `neginfif`. 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 3dffc00..332fd2f 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 @@ -69,6 +69,11 @@ addFunctionMapping("ifinf", "if-inf"); // ifinf, internal: if-inf addFunctionMapping("ifnan", "if-nan"); // ifnan, internal: if-nan addFunctionMapping("ifnanorinf", "if-nan-or-inf"); // ifnanorinf, internal: if-nan-or-inf + addFunctionMapping("missingif", "missing-if"); // missingif, internal: missing-if + addFunctionMapping("nanif", "nan-if"); // nanif, internal: nan-if + addFunctionMapping("neginfif", "neginf-if"); // neginfif, internal: neginf-if + addFunctionMapping("nullif", "null-if"); // nullif, internal: null-if + addFunctionMapping("posinfif", "posinf-if"); // posinfif, internal: posinf-if addFunctionMapping("toarray", "to-array"); // toarray, internal: to-array addFunctionMapping("toatomic", "to-atomic"); // toatomic, internal: to-atomic addFunctionMapping("toatom", "to-atomic"); // toatom, internal: to-atomic diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java index dd199e7..8071967 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java @@ -62,6 +62,7 @@ import org.apache.asterix.om.typecomputer.impl.CollectionMemberResultType; import org.apache.asterix.om.typecomputer.impl.CollectionToSequenceTypeComputer; import org.apache.asterix.om.typecomputer.impl.ConcatNonNullTypeComputer; +import org.apache.asterix.om.typecomputer.impl.DoubleIfTypeComputer; import org.apache.asterix.om.typecomputer.impl.FieldAccessByIndexResultType; import org.apache.asterix.om.typecomputer.impl.FieldAccessByNameResultType; import org.apache.asterix.om.typecomputer.impl.FieldAccessNestedResultType; @@ -74,8 +75,10 @@ import org.apache.asterix.om.typecomputer.impl.InjectFailureTypeComputer; import org.apache.asterix.om.typecomputer.impl.LocalAvgTypeComputer; import org.apache.asterix.om.typecomputer.impl.MinMaxAggTypeComputer; +import org.apache.asterix.om.typecomputer.impl.MissingIfTypeComputer; import org.apache.asterix.om.typecomputer.impl.NonTaggedGetItemResultType; import org.apache.asterix.om.typecomputer.impl.NotUnknownTypeComputer; +import org.apache.asterix.om.typecomputer.impl.NullIfTypeComputer; import org.apache.asterix.om.typecomputer.impl.NullableDoubleTypeComputer; import org.apache.asterix.om.typecomputer.impl.NumericAddSubMulDivTypeComputer; import org.apache.asterix.om.typecomputer.impl.NumericAggTypeComputer; @@ -1001,6 +1004,15 @@ public static final FunctionIdentifier IF_NAN_OR_INF = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "if-nan-or-inf", FunctionIdentifier.VARARGS); + public static final FunctionIdentifier MISSING_IF = + new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "missing-if", 2); + public static final FunctionIdentifier NULL_IF = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "null-if", 2); + public static final FunctionIdentifier NAN_IF = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "nan-if", 2); + public static final FunctionIdentifier POSINF_IF = + new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "posinf-if", 2); + public static final FunctionIdentifier NEGINF_IF = + new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "neginf-if", 2); + public static final FunctionIdentifier TO_ATOMIC = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "to-atomic", 1); public static final FunctionIdentifier TO_ARRAY = @@ -1106,9 +1118,6 @@ addPrivateFunction(GRAM_TOKENS, OrderedListOfAStringTypeComputer.INSTANCE, true); addPrivateFunction(HASHED_GRAM_TOKENS, OrderedListOfAInt32TypeComputer.INSTANCE, true); addPrivateFunction(HASHED_WORD_TOKENS, OrderedListOfAInt32TypeComputer.INSTANCE, true); - addFunction(IF_MISSING_OR_NULL, IfMissingOrNullTypeComputer.INSTANCE, true); - addFunction(IF_MISSING, IfMissingTypeComputer.INSTANCE, true); - addFunction(IF_NULL, IfNullTypeComputer.INSTANCE, true); addPrivateFunction(INDEX_SEARCH, AnyTypeComputer.INSTANCE, true); addFunction(INT8_CONSTRUCTOR, AInt8TypeComputer.INSTANCE, true); addFunction(INT16_CONSTRUCTOR, AInt16TypeComputer.INSTANCE, true); @@ -1145,9 +1154,6 @@ addFunction(NUMERIC_ROUND_HALF_TO_EVEN, NumericUnaryFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_ROUND_HALF_TO_EVEN2, NumericRound2TypeComputer.INSTANCE, true); addFunction(NUMERIC_TRUNC, NumericRound2TypeComputer.INSTANCE, true); - addFunction(IF_INF, IfNanOrInfTypeComputer.INSTANCE, true); - addFunction(IF_NAN, IfNanOrInfTypeComputer.INSTANCE, true); - addFunction(IF_NAN_OR_INF, IfNanOrInfTypeComputer.INSTANCE, true); addFunction(BINARY_LENGTH, UnaryBinaryInt64TypeComputer.INSTANCE, true); addFunction(PARSE_BINARY, ABinaryTypeComputer.INSTANCE, true); @@ -1213,6 +1219,19 @@ addFunction(TO_OBJECT, ToObjectTypeComputer.INSTANCE, true); addFunction(TO_STRING, AStringTypeComputer.INSTANCE, true); + addFunction(IF_INF, IfNanOrInfTypeComputer.INSTANCE, true); + addFunction(IF_MISSING, IfMissingTypeComputer.INSTANCE, true); + addFunction(IF_MISSING_OR_NULL, IfMissingOrNullTypeComputer.INSTANCE, true); + addFunction(IF_NULL, IfNullTypeComputer.INSTANCE, true); + addFunction(IF_NAN, IfNanOrInfTypeComputer.INSTANCE, true); + addFunction(IF_NAN_OR_INF, IfNanOrInfTypeComputer.INSTANCE, true); + + addFunction(MISSING_IF, MissingIfTypeComputer.INSTANCE, true); + addFunction(NULL_IF, NullIfTypeComputer.INSTANCE, true); + addFunction(NAN_IF, DoubleIfTypeComputer.INSTANCE, true); + addFunction(POSINF_IF, DoubleIfTypeComputer.INSTANCE, true); + addFunction(NEGINF_IF, DoubleIfTypeComputer.INSTANCE, true); + // Aggregate Functions addFunction(MAX, MinMaxAggTypeComputer.INSTANCE, true); addPrivateFunction(LOCAL_MAX, MinMaxAggTypeComputer.INSTANCE, true); diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/DoubleIfTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/DoubleIfTypeComputer.java new file mode 100644 index 0000000..105ea52 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/DoubleIfTypeComputer.java @@ -0,0 +1,38 @@ +/* + * 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.om.typecomputer.impl; + +import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; + +public class DoubleIfTypeComputer extends AbstractResultTypeComputer { + + public static final DoubleIfTypeComputer INSTANCE = new DoubleIfTypeComputer(); + + @Override + public IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException { + IAType inputType = strippedInputTypes[0]; + return inputType.getTypeTag() == ATypeTag.DOUBLE ? inputType : BuiltinType.ANY; + } +} diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MissingIfTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MissingIfTypeComputer.java new file mode 100644 index 0000000..bb5203e --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MissingIfTypeComputer.java @@ -0,0 +1,38 @@ +/* + * 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.om.typecomputer.impl; + +import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.AUnionType; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; + +public class MissingIfTypeComputer extends AbstractResultTypeComputer { + + public static final MissingIfTypeComputer INSTANCE = new MissingIfTypeComputer(); + + @Override + public IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException { + IAType inputType = strippedInputTypes[0]; + return inputType.getTypeTag() == ATypeTag.ANY ? inputType : AUnionType.createMissableType(inputType); + } +} diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NullIfTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NullIfTypeComputer.java new file mode 100644 index 0000000..590d8f6 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NullIfTypeComputer.java @@ -0,0 +1,38 @@ +/* + * 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.om.typecomputer.impl; + +import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.AUnionType; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; + +public class NullIfTypeComputer extends AbstractResultTypeComputer { + + public static final NullIfTypeComputer INSTANCE = new NullIfTypeComputer(); + + @Override + public IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException { + IAType inputType = strippedInputTypes[0]; + return inputType.getTypeTag() == ATypeTag.ANY ? inputType : AUnionType.createNullableType(inputType); + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java index 620c543..b8c5f19 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java @@ -20,18 +20,10 @@ import java.io.DataOutput; -import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider; -import org.apache.asterix.om.base.ABoolean; -import org.apache.asterix.om.base.ANull; import org.apache.asterix.om.types.ATypeTag; -import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.EnumDeserializer; import org.apache.asterix.om.types.hierachy.ATypeHierarchy; -import org.apache.asterix.runtime.exceptions.UnsupportedTypeException; import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; -import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; -import org.apache.hyracks.api.context.IHyracksTaskContext; -import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.data.std.api.IPointable; import org.apache.hyracks.data.std.primitive.TaggedValuePointable; @@ -41,85 +33,38 @@ public abstract class AbstractComparisonEvaluator implements IScalarEvaluator { - protected ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage(); - protected DataOutput out = resultStorage.getDataOutput(); - protected TaggedValuePointable argLeft = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable(); - protected TaggedValuePointable argRight = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable(); - protected IPointable outLeft = VoidPointable.FACTORY.createPointable(); - protected IPointable outRight = VoidPointable.FACTORY.createPointable(); - protected IScalarEvaluator evalLeft; - protected IScalarEvaluator evalRight; - private ComparisonHelper ch = new ComparisonHelper(); + protected final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage(); + protected final DataOutput out = resultStorage.getDataOutput(); + protected final TaggedValuePointable argLeft = + (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable(); + protected final TaggedValuePointable argRight = + (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable(); + protected final IPointable outLeft = VoidPointable.FACTORY.createPointable(); + protected final IPointable outRight = VoidPointable.FACTORY.createPointable(); + protected final IScalarEvaluator evalLeft; + protected final IScalarEvaluator evalRight; + private final ComparisonHelper ch = new ComparisonHelper(); - @SuppressWarnings("unchecked") - protected ISerializerDeserializer<ABoolean> serde = - SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN); - @SuppressWarnings("unchecked") - protected ISerializerDeserializer<ANull> nullSerde = - SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL); - - public AbstractComparisonEvaluator(IScalarEvaluatorFactory evalLeftFactory, - IScalarEvaluatorFactory evalRightFactory, IHyracksTaskContext context) throws HyracksDataException { - this.evalLeft = evalLeftFactory.createScalarEvaluator(context); - this.evalRight = evalRightFactory.createScalarEvaluator(context); + public AbstractComparisonEvaluator(IScalarEvaluator evalLeft, IScalarEvaluator evalRight) { + this.evalLeft = evalLeft; + this.evalRight = evalRight; } @Override public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException { - resultStorage.reset(); - // Evaluates input args. evalLeft.evaluate(tuple, argLeft); evalRight.evaluate(tuple, argRight); argLeft.getValue(outLeft); argRight.getValue(outRight); - // checks whether we can apply >, >=, <, and <= to the given type since - // these operations cannot be defined for certain types. - if (isTotallyOrderable()) { - checkTotallyOrderable(); - } - - // Checks whether two types are comparable - if (comparabilityCheck()) { - // Two types can be compared - int r = compareResults(); - ABoolean b = getComparisonResult(r) ? ABoolean.TRUE : ABoolean.FALSE; - serde.serialize(b, out); - } else { - // result:NULL - two types cannot be compared. - nullSerde.serialize(ANull.NULL, out); - } - result.set(resultStorage); + evaluateImpl(result); } - protected abstract boolean isTotallyOrderable(); - - protected abstract boolean getComparisonResult(int r); - - // checks whether we can apply >, >=, <, and <= operations to the given type since - // these operations can not be defined for certain types. - protected void checkTotallyOrderable() throws HyracksDataException { - if (argLeft.getLength() != 0) { - ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argLeft.getTag()); - switch (typeTag) { - case DURATION: - case INTERVAL: - case LINE: - case POINT: - case POINT3D: - case POLYGON: - case CIRCLE: - case RECTANGLE: - throw new UnsupportedTypeException(ComparisonHelper.COMPARISON, argLeft.getTag()); - default: - return; - } - } - } + protected abstract void evaluateImpl(IPointable result) throws HyracksDataException; // checks whether two types are comparable - protected boolean comparabilityCheck() { + boolean comparabilityCheck() { // Checks whether two types are comparable or not ATypeTag typeTag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argLeft.getTag()); ATypeTag typeTag2 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argRight.getTag()); @@ -128,10 +73,8 @@ return ATypeHierarchy.isCompatible(typeTag1, typeTag2); } - protected int compareResults() throws HyracksDataException { - int result = ch.compare(EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argLeft.getTag()), + int compare() throws HyracksDataException { + return ch.compare(EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argLeft.getTag()), EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argRight.getTag()), outLeft, outRight); - return result; } - } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractIfEqualsEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractIfEqualsEvaluator.java new file mode 100644 index 0000000..c267bab --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractIfEqualsEvaluator.java @@ -0,0 +1,44 @@ +/* + * 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.comparisons; + +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.data.std.api.IPointable; + +public abstract class AbstractIfEqualsEvaluator extends AbstractComparisonEvaluator { + + AbstractIfEqualsEvaluator(IScalarEvaluator evalLeft, IScalarEvaluator evalRight) { + super(evalLeft, evalRight); + } + + @Override + protected void evaluateImpl(IPointable result) throws HyracksDataException { + if (comparabilityCheck() && compare() == 0) { + resultStorage.reset(); + writeEqualsResult(); + result.set(resultStorage); + } else { + result.set(argLeft); + } + } + + protected abstract void writeEqualsResult() throws HyracksDataException; +} \ No newline at end of file diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractValueComparisonEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractValueComparisonEvaluator.java new file mode 100644 index 0000000..446fed7 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractValueComparisonEvaluator.java @@ -0,0 +1,94 @@ +/* + * 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.comparisons; + +import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider; +import org.apache.asterix.om.base.ABoolean; +import org.apache.asterix.om.base.ANull; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.om.types.EnumDeserializer; +import org.apache.asterix.runtime.exceptions.UnsupportedTypeException; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; +import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.data.std.api.IPointable; + +public abstract class AbstractValueComparisonEvaluator extends AbstractComparisonEvaluator { + @SuppressWarnings("unchecked") + protected ISerializerDeserializer<ABoolean> serde = + SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN); + @SuppressWarnings("unchecked") + protected ISerializerDeserializer<ANull> nullSerde = + SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL); + + public AbstractValueComparisonEvaluator(IScalarEvaluator evalLeft, IScalarEvaluator evalRight) { + super(evalLeft, evalRight); + } + + @Override + protected void evaluateImpl(IPointable result) throws HyracksDataException { + resultStorage.reset(); + + // checks whether we can apply >, >=, <, and <= to the given type since + // these operations cannot be defined for certain types. + if (isTotallyOrderable()) { + checkTotallyOrderable(); + } + + // Checks whether two types are comparable + if (comparabilityCheck()) { + // Two types can be compared + int r = compare(); + ABoolean b = getComparisonResult(r) ? ABoolean.TRUE : ABoolean.FALSE; + serde.serialize(b, out); + } else { + // result:NULL - two types cannot be compared. + nullSerde.serialize(ANull.NULL, out); + } + result.set(resultStorage); + } + + protected abstract boolean isTotallyOrderable(); + + protected abstract boolean getComparisonResult(int r); + + // checks whether we can apply >, >=, <, and <= operations to the given type since + // these operations can not be defined for certain types. + protected void checkTotallyOrderable() throws HyracksDataException { + if (argLeft.getLength() != 0) { + ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argLeft.getTag()); + switch (typeTag) { + case DURATION: + case INTERVAL: + case LINE: + case POINT: + case POINT3D: + case POLYGON: + case CIRCLE: + case RECTANGLE: + throw new UnsupportedTypeException(ComparisonHelper.COMPARISON, argLeft.getTag()); + default: + return; + } + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/EqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/EqualsDescriptor.java index b277885..c4fafa1 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/EqualsDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/EqualsDescriptor.java @@ -50,7 +50,8 @@ @Override public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { - return new AbstractComparisonEvaluator(args[0], args[1], ctx) { + return new AbstractValueComparisonEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { @Override protected boolean getComparisonResult(int r) { diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanDescriptor.java index 2826279..6a41104 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanDescriptor.java @@ -50,7 +50,8 @@ @Override public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { - return new AbstractComparisonEvaluator(args[0], args[1], ctx) { + return new AbstractValueComparisonEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { @Override protected boolean getComparisonResult(int r) { diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanOrEqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanOrEqualsDescriptor.java index e12dd71..c468aac 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanOrEqualsDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/GreaterThanOrEqualsDescriptor.java @@ -50,7 +50,8 @@ @Override public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { - return new AbstractComparisonEvaluator(args[0], args[1], ctx) { + return new AbstractValueComparisonEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { @Override protected boolean getComparisonResult(int r) { diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanDescriptor.java index 7e97dfa..4eac444 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanDescriptor.java @@ -50,7 +50,8 @@ @Override public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { - return new AbstractComparisonEvaluator(args[0], args[1], ctx) { + return new AbstractValueComparisonEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { @Override protected boolean getComparisonResult(int r) { diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanOrEqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanOrEqualsDescriptor.java index 947dea1..ad365d6 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanOrEqualsDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/LessThanOrEqualsDescriptor.java @@ -50,7 +50,8 @@ @Override public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { - return new AbstractComparisonEvaluator(args[0], args[1], ctx) { + return new AbstractValueComparisonEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { @Override protected boolean getComparisonResult(int r) { diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/MissingIfEqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/MissingIfEqualsDescriptor.java new file mode 100644 index 0000000..5b4f5e6 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/MissingIfEqualsDescriptor.java @@ -0,0 +1,72 @@ +/* + * 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.comparisons; + +import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider; +import org.apache.asterix.om.base.AMissing; +import org.apache.asterix.om.functions.BuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +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; +import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class MissingIfEqualsDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new MissingIfEqualsDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.MISSING_IF; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { + return new AbstractIfEqualsEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { + + @SuppressWarnings("unchecked") + final ISerializerDeserializer<AMissing> missingSerde = + SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING); + + @Override + protected void writeEqualsResult() throws HyracksDataException { + missingSerde.serialize(AMissing.MISSING, out); + } + }; + } + }; + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NanIfEqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NanIfEqualsDescriptor.java new file mode 100644 index 0000000..7c6b5b2 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NanIfEqualsDescriptor.java @@ -0,0 +1,75 @@ +/* + * 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.comparisons; + +import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider; +import org.apache.asterix.om.base.ADouble; +import org.apache.asterix.om.base.AMutableDouble; +import org.apache.asterix.om.functions.BuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +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; +import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class NanIfEqualsDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NanIfEqualsDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.NAN_IF; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { + return new AbstractIfEqualsEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { + + final AMutableDouble equalsResult = new AMutableDouble(Double.NaN); + + @SuppressWarnings("unchecked") + final ISerializerDeserializer<ADouble> doubleSerde = + SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE); + + @Override + protected void writeEqualsResult() throws HyracksDataException { + doubleSerde.serialize(equalsResult, out); + } + }; + } + }; + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NegInfIfEqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NegInfIfEqualsDescriptor.java new file mode 100644 index 0000000..1c40357 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NegInfIfEqualsDescriptor.java @@ -0,0 +1,75 @@ +/* + * 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.comparisons; + +import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider; +import org.apache.asterix.om.base.ADouble; +import org.apache.asterix.om.base.AMutableDouble; +import org.apache.asterix.om.functions.BuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +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; +import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class NegInfIfEqualsDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NegInfIfEqualsDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.NEGINF_IF; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { + return new AbstractIfEqualsEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { + + final AMutableDouble equalsResult = new AMutableDouble(Double.NEGATIVE_INFINITY); + + @SuppressWarnings("unchecked") + final ISerializerDeserializer<ADouble> doubleSerde = + SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE); + + @Override + protected void writeEqualsResult() throws HyracksDataException { + doubleSerde.serialize(equalsResult, out); + } + }; + } + }; + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NotEqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NotEqualsDescriptor.java index bfd5c98..17515af 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NotEqualsDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NotEqualsDescriptor.java @@ -50,7 +50,8 @@ @Override public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { - return new AbstractComparisonEvaluator(args[0], args[1], ctx) { + return new AbstractValueComparisonEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { @Override protected boolean getComparisonResult(int r) { diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NullIfEqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NullIfEqualsDescriptor.java new file mode 100644 index 0000000..c09a75c --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/NullIfEqualsDescriptor.java @@ -0,0 +1,72 @@ +/* + * 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.comparisons; + +import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider; +import org.apache.asterix.om.base.ANull; +import org.apache.asterix.om.functions.BuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +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; +import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class NullIfEqualsDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NullIfEqualsDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.NULL_IF; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { + return new AbstractIfEqualsEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { + + @SuppressWarnings("unchecked") + final ISerializerDeserializer<ANull> nullSerde = + SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL); + + @Override + protected void writeEqualsResult() throws HyracksDataException { + nullSerde.serialize(ANull.NULL, out); + } + }; + } + }; + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/PosInfIfEqualsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/PosInfIfEqualsDescriptor.java new file mode 100644 index 0000000..6a969b2 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/PosInfIfEqualsDescriptor.java @@ -0,0 +1,75 @@ +/* + * 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.comparisons; + +import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider; +import org.apache.asterix.om.base.ADouble; +import org.apache.asterix.om.base.AMutableDouble; +import org.apache.asterix.om.functions.BuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +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; +import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class PosInfIfEqualsDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new PosInfIfEqualsDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.POSINF_IF; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { + return new AbstractIfEqualsEvaluator(args[0].createScalarEvaluator(ctx), + args[1].createScalarEvaluator(ctx)) { + + final AMutableDouble equalsResult = new AMutableDouble(Double.POSITIVE_INFINITY); + + @SuppressWarnings("unchecked") + final ISerializerDeserializer<ADouble> doubleSerde = + SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE); + + @Override + protected void writeEqualsResult() throws HyracksDataException { + doubleSerde.serialize(equalsResult, out); + } + }; + } + }; + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java index 245eb25..32b7b7f 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java @@ -104,7 +104,12 @@ import org.apache.asterix.runtime.evaluators.comparisons.GreaterThanOrEqualsDescriptor; import org.apache.asterix.runtime.evaluators.comparisons.LessThanDescriptor; import org.apache.asterix.runtime.evaluators.comparisons.LessThanOrEqualsDescriptor; +import org.apache.asterix.runtime.evaluators.comparisons.MissingIfEqualsDescriptor; +import org.apache.asterix.runtime.evaluators.comparisons.NanIfEqualsDescriptor; +import org.apache.asterix.runtime.evaluators.comparisons.NegInfIfEqualsDescriptor; import org.apache.asterix.runtime.evaluators.comparisons.NotEqualsDescriptor; +import org.apache.asterix.runtime.evaluators.comparisons.NullIfEqualsDescriptor; +import org.apache.asterix.runtime.evaluators.comparisons.PosInfIfEqualsDescriptor; import org.apache.asterix.runtime.evaluators.constructors.ABinaryBase64StringConstructorDescriptor; import org.apache.asterix.runtime.evaluators.constructors.ABinaryHexStringConstructorDescriptor; import org.apache.asterix.runtime.evaluators.constructors.ABooleanConstructorDescriptor; @@ -516,6 +521,13 @@ fc.addGenerated(LessThanOrEqualsDescriptor.FACTORY); fc.addGenerated(NotEqualsDescriptor.FACTORY); + // If-Equals functions + fc.addGenerated(MissingIfEqualsDescriptor.FACTORY); + fc.addGenerated(NullIfEqualsDescriptor.FACTORY); + fc.addGenerated(NanIfEqualsDescriptor.FACTORY); + fc.addGenerated(PosInfIfEqualsDescriptor.FACTORY); + fc.addGenerated(NegInfIfEqualsDescriptor.FACTORY); + // Binary functions fc.addGenerated(BinaryLengthDescriptor.FACTORY); fc.addGenerated(ParseBinaryDescriptor.FACTORY); -- To view, visit https://asterix-gerrit.ics.uci.edu/2616 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5399cae1a225b1881d67b87541e46a9d4fe158ec Gerrit-PatchSet: 2 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Dmitry Lychagin <dmitry.lycha...@couchbase.com> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Dmitry Lychagin <dmitry.lycha...@couchbase.com> Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Gerrit-Reviewer: Till Westmann <ti...@apache.org>