Dmitry Lychagin has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/2416
Change subject: [ASTERIXDB-2294][FUN] Implement is_atomic() ...................................................................... [ASTERIXDB-2294][FUN] Implement is_atomic() - user model changes: yes - storage format changes: no - interface changes: no Details: - Implement is_atomic() function with aliases isatomic(), isatom() - Add testcases and documentation Change-Id: Ib979f4fe2fdce7575d13a259ac241d58d9fc6ae2 --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isatomic/isatomic.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/types/isatomic/isatomic.1.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-doc/src/main/markdown/builtins/11_type.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-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsAtomicDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java 8 files changed, 142 insertions(+), 0 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/16/2416/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isatomic/isatomic.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isatomic/isatomic.1.query.sqlpp new file mode 100644 index 0000000..d8b2389 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isatomic/isatomic.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": isatomic(true), + "b": isatomic(false), + "c": is_atomic(null), + "d": is_atomic(missing), + "e": isatom("d"), + "f": isatom4.0), + "g": isatom(5), + "h": isatom(["1", 2]), + "i": isatom({"a":1}) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isatomic/isatomic.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isatomic/isatomic.1.adm new file mode 100644 index 0000000..b6cd2d0 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isatomic/isatomic.1.adm @@ -0,0 +1 @@ +{ "a": true, "b": true, "c": null, "e": true, "f": true, "g": true, "h": false, "i": false } 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 909b523..541cd1b 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -9013,6 +9013,11 @@ </compilation-unit> </test-case> <test-case FilePath="types"> + <compilation-unit name="isatomic"> + <output-dir compare="Text">isatomic</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="types"> <compilation-unit name="isboolean"> <output-dir compare="Text">isboolean</output-dir> </compilation-unit> diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/11_type.md b/asterixdb/asterix-doc/src/main/markdown/builtins/11_type.md index a2b2555..ba3a735 100644 --- a/asterixdb/asterix-doc/src/main/markdown/builtins/11_type.md +++ b/asterixdb/asterix-doc/src/main/markdown/builtins/11_type.md @@ -53,6 +53,38 @@ The function has an alias `isarray`. +### is_atomic (isatomic, isatom) ### + * Syntax: + + is_atomic(expr) + + * Checks whether the given expression is evaluated to be a value of a [primitive](../datamodel.html#PrimitiveTypes) type. + * Arguments: + * `expr` : an expression (any type is allowed). + * Return Value: + * a `boolean` on whether the argument is a primitive type or not, + * a `missing` if the argument is a `missing` value, + * a `null` if the argument is a `null` value. + + * Example: + + { + "a": is_atomic(true), + "b": is_atomic(false), + "c": isatomic(null), + "d": isatomic(missing), + "e": isatomic("d"), + "f": isatom(4.0), + "g": isatom(5), + "h": isatom(["1", 2]), + "i": isatom({"a":1}) + }; + +* The expected result is: + + { "a": true, "b": true, "c": null, "e": true, "f": true, "g": true, "h": false, "i": false } + + The function has two aliases, `isatomic` or `isatom`. ### is_boolean (isboolean, isbool) ### * Syntax: 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 092de98..12fe01e 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 @@ -53,6 +53,8 @@ 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("isatomic", "is-atomic"); // isatomic, internal: is-atomic + FUNCTION_NAME_MAP.put("isatom", "is-atomic"); // isatom, internal: is-atomic 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 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 d749899..40c9c7b 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 @@ -825,6 +825,8 @@ public static final FunctionIdentifier IS_NULL = AlgebricksBuiltinFunctions.IS_NULL; public static final FunctionIdentifier IS_UNKNOWN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-unknown", 1); + public static final FunctionIdentifier IS_ATOMIC = + new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-atomic", 1); public static final FunctionIdentifier IS_BOOLEAN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-boolean", 1); public static final FunctionIdentifier IS_NUMBER = @@ -885,6 +887,7 @@ addFunction(IS_UNKNOWN, BooleanOnlyTypeComputer.INSTANCE, true); addFunction(IS_NULL, BooleanOrMissingTypeComputer.INSTANCE, true); addFunction(IS_SYSTEM_NULL, ABooleanTypeComputer.INSTANCE, true); + addFunction(IS_ATOMIC, ABooleanTypeComputer.INSTANCE, true); addFunction(IS_BOOLEAN, ABooleanTypeComputer.INSTANCE, true); addFunction(IS_NUMBER, ABooleanTypeComputer.INSTANCE, true); addFunction(IS_STRING, ABooleanTypeComputer.INSTANCE, true); diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsAtomicDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsAtomicDescriptor.java new file mode 100644 index 0000000..124ffa2 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsAtomicDescriptor.java @@ -0,0 +1,67 @@ +/* + * 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.BuiltinFunctions; +import org.apache.asterix.om.functions.IFunctionDescriptor; +import org.apache.asterix.om.functions.IFunctionDescriptorFactory; +import org.apache.asterix.om.types.EnumDeserializer; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +import org.apache.asterix.runtime.evaluators.common.AbstractTypeCheckEvaluator; +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.exceptions.HyracksDataException; + +public class IsAtomicDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new IsAtomicDescriptor(); + } + }; + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException { + final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx); + return new AbstractTypeCheckEvaluator(eval) { + @Override + protected Value isMatch(byte typeTag) { + return EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(typeTag).isDerivedType() ? Value.FALSE + : Value.TRUE; + + } + }; + } + }; + } + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.IS_ATOMIC; + } +} 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 f3eb6c9..f0ddcf5 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 @@ -167,6 +167,7 @@ import org.apache.asterix.runtime.evaluators.functions.IfNullDescriptor; import org.apache.asterix.runtime.evaluators.functions.InjectFailureDescriptor; import org.apache.asterix.runtime.evaluators.functions.IsArrayDescriptor; +import org.apache.asterix.runtime.evaluators.functions.IsAtomicDescriptor; import org.apache.asterix.runtime.evaluators.functions.IsBooleanDescriptor; import org.apache.asterix.runtime.evaluators.functions.IsMissingDescriptor; import org.apache.asterix.runtime.evaluators.functions.IsNullDescriptor; @@ -707,6 +708,7 @@ fc.addGenerated(DurationFromIntervalDescriptor.FACTORY); // Type functions. + fc.addGenerated(IsAtomicDescriptor.FACTORY); fc.addGenerated(IsBooleanDescriptor.FACTORY); fc.addGenerated(IsNumberDescriptor.FACTORY); fc.addGenerated(IsStringDescriptor.FACTORY); -- To view, visit https://asterix-gerrit.ics.uci.edu/2416 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib979f4fe2fdce7575d13a259ac241d58d9fc6ae2 Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Dmitry Lychagin <dmitry.lycha...@couchbase.com>