Hussain Towaileb has uploaded this change for review. (
https://asterix-gerrit.ics.uci.edu/3377
Change subject: [WIP] Introduce bitwise functions
......................................................................
[WIP] Introduce bitwise functions
Change-Id: I70a6376d6ca12da55eeff88fa0b1c85f970ef8e6
---
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/BitwiseTypeComputer.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/AbstractBitwiseEvaluator.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitAndDescriptor.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitAndEvaluator.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitOrDescriptor.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitOrEvaluator.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitXorDescriptor.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitXorEvaluator.java
M
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
10 files changed, 572 insertions(+), 0 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/77/3377/1
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 df2a868..1cbb0b6 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
@@ -67,6 +67,7 @@
import org.apache.asterix.om.typecomputer.impl.ArrayIfNullTypeComputer;
import org.apache.asterix.om.typecomputer.impl.ArrayRangeTypeComputer;
import org.apache.asterix.om.typecomputer.impl.ArrayRepeatTypeComputer;
+import org.apache.asterix.om.typecomputer.impl.BitwiseTypeComputer;
import org.apache.asterix.om.typecomputer.impl.BooleanFunctionTypeComputer;
import org.apache.asterix.om.typecomputer.impl.BooleanOnlyTypeComputer;
import org.apache.asterix.om.typecomputer.impl.BooleanOrMissingTypeComputer;
@@ -378,6 +379,24 @@
new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"find-binary", 2);
public static final FunctionIdentifier FIND_BINARY_FROM =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"find-binary", 3);
+
+ // bitwise functions
+ public static final FunctionIdentifier BIT_AND =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bitand",
FunctionIdentifier.VARARGS);
+ public static final FunctionIdentifier BIT_OR =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bitor",
FunctionIdentifier.VARARGS);
+ public static final FunctionIdentifier BIT_XOR =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bitxor",
FunctionIdentifier.VARARGS);
+ public static final FunctionIdentifier BIT_NOT = new
FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bitnot", 1);
+ public static final FunctionIdentifier BIT_CLEAR =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bitclear",
1);
+ public static final FunctionIdentifier BIT_SHIFT =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bitshift",
2);
+ public static final FunctionIdentifier BIT_SET = new
FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bitset", 2);
+ public static final FunctionIdentifier BIT_TEST =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bittest", 2);
+ public static final FunctionIdentifier BIT_COUNT =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "bitcount",
1);
// String functions
public static final FunctionIdentifier STRING_EQUAL =
@@ -1675,6 +1694,10 @@
addFunction(FIND_BINARY, AInt64TypeComputer.INSTANCE, true);
addFunction(FIND_BINARY_FROM, AInt64TypeComputer.INSTANCE, true);
+ addFunction(BIT_AND, BitwiseTypeComputer.INSTANCE, true);
+ addFunction(BIT_OR, BitwiseTypeComputer.INSTANCE, true);
+ addFunction(BIT_XOR, BitwiseTypeComputer.INSTANCE, true);
+
addFunction(STRING_CONSTRUCTOR, AStringTypeComputer.INSTANCE, true);
addFunction(STRING_LIKE, BooleanFunctionTypeComputer.INSTANCE, true);
addFunction(STRING_CONTAINS, ABooleanTypeComputer.INSTANCE, true);
diff --git
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/BitwiseTypeComputer.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/BitwiseTypeComputer.java
new file mode 100644
index 0000000..06f8aca
--- /dev/null
+++
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/BitwiseTypeComputer.java
@@ -0,0 +1,55 @@
+/*
+ * 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.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 BitwiseTypeComputer extends AbstractResultTypeComputer {
+
+ public static final BitwiseTypeComputer INSTANCE = new
BitwiseTypeComputer();
+
+ private BitwiseTypeComputer() {
+ }
+
+ @Override
+ protected IAType getResultType(ILogicalExpression expr, IAType...
strippedInputTypes) throws AlgebricksException {
+
+ // Check that all arguments are of valid type, otherwise a null is
return
+ for (IAType type : strippedInputTypes) {
+ switch (type.getTypeTag()) {
+ case TINYINT:
+ case SMALLINT:
+ case INTEGER:
+ case BIGINT:
+ case FLOAT:
+ case DOUBLE:
+ case ANY:
+ continue;
+ default:
+ return BuiltinType.ANULL;
+ }
+ }
+
+ return BuiltinType.AINT64;
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/AbstractBitwiseEvaluator.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/AbstractBitwiseEvaluator.java
new file mode 100644
index 0000000..16fd043
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/AbstractBitwiseEvaluator.java
@@ -0,0 +1,210 @@
+/*
+ * 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.bitwise;
+
+import
org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import
org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import
org.apache.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import
org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import
org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import
org.apache.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
+import org.apache.asterix.om.base.AMutableInt64;
+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.evaluators.functions.AbstractScalarEval;
+import org.apache.asterix.runtime.evaluators.functions.PointableHelper;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
+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;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public abstract class AbstractBitwiseEvaluator extends AbstractScalarEval {
+
+ // Result members
+ private final AMutableInt64 aMutableInt64 = new AMutableInt64(0);
+ private final ArrayBackedValueStorage resultStorage = new
ArrayBackedValueStorage();
+
+ // Evaluators and Pointables
+ private final IScalarEvaluator[] argEvaluators;
+ private final IPointable[] argPointables;
+
+ // Serializer/Deserializer
+ @SuppressWarnings("rawtypes")
+ private final ISerializerDeserializer aInt64Serde =
+
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
+
+ AbstractBitwiseEvaluator(IHyracksTaskContext context,
IScalarEvaluatorFactory[] argEvaluatorFactories,
+ FunctionIdentifier functionIdentifier, SourceLocation
sourceLocation) throws HyracksDataException {
+ super(sourceLocation, functionIdentifier);
+
+ // Evaluators and Pointables
+ argPointables = new IPointable[argEvaluatorFactories.length];
+ argEvaluators = new IScalarEvaluator[argEvaluatorFactories.length];
+ for (int i = 0; i < argEvaluatorFactories.length; i++) {
+ argEvaluators[i] =
argEvaluatorFactories[i].createScalarEvaluator(context);
+ argPointables[i] = new VoidPointable();
+ }
+ }
+
+ // Abstract method
+ abstract long applyBitwiseOperation(long value1, long value2);
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void evaluate(IFrameTupleReference tuple, IPointable result) throws
HyracksDataException {
+ resultStorage.reset();
+ boolean isReturnNull = false;
+
+ // Evaluate and check the arguments (Missing/Null checks)
+ for (int i = 0; i < argEvaluators.length; i++) {
+ argEvaluators[i].evaluate(tuple, argPointables[i]);
+
+ if (PointableHelper.checkAndSetMissingOrNull(result,
argPointables[i])) {
+ if (result.getByteArray()[0] ==
ATypeTag.SERIALIZED_MISSING_TYPE_TAG) {
+ return;
+ }
+
+ // null value, but check other arguments for missing first
(higher priority)
+ isReturnNull = true;
+ }
+ }
+
+ if (isReturnNull) {
+ PointableHelper.setNull(result);
+ return;
+ }
+
+ // First argument
+ byte[] bytes = argPointables[0].getByteArray();
+ int startOffset = argPointables[0].getStartOffset();
+ ATypeTag typeTag =
EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[startOffset]);
+
+ // Validity check
+ if (isInvalidValue(bytes, startOffset + 1, typeTag)) {
+ PointableHelper.setNull(result);
+ return;
+ }
+
+ // This will hold each calculated result
+ long bitwiseResult = getLongValue(bytes, startOffset + 1, typeTag, 0);
+
+ // Loop and do the bitwise operation for all the arguments (start from
index 1, we did first item above)
+ for (int i = 1; i < argPointables.length; i++) {
+ bytes = argPointables[i].getByteArray();
+ startOffset = argPointables[i].getStartOffset();
+ typeTag =
EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[startOffset]);
+
+ if (isInvalidValue(bytes, startOffset + 1, typeTag)) {
+ PointableHelper.setNull(result);
+ return;
+ }
+
+ long value = getLongValue(bytes, startOffset + 1, typeTag, i);
+ bitwiseResult = applyBitwiseOperation(bitwiseResult, value);
+ }
+
+ // Write the result
+ aMutableInt64.setValue(bitwiseResult);
+ aInt64Serde.serialize(aMutableInt64, resultStorage.getDataOutput());
+ result.set(resultStorage);
+ }
+
+ /**
+ * This method checks if the provided value is invalid. The value is valid
if the value is a valid long
+ * number, or in case of float and double, it is a number with a decimal 0
(e.g. 1.0, 2.0, but not 2.5)
+ *
+ * @param bytes data bytes
+ * @param startOffset start offset
+ * @param typeTag ATypeTag of the value
+ *
+ * @return returns {@code true} if it's an invalid value, {@code false}
otherwise.
+ */
+ private boolean isInvalidValue(byte[] bytes, int startOffset, ATypeTag
typeTag) {
+
+ // If it can't be promoted to double, it's not a number
+ if (!ATypeHierarchy.canPromote(typeTag, ATypeTag.DOUBLE)) {
+ return true;
+ }
+
+ // Float check (1.0, 2.0 are fine, but 1.5 is not)
+ if (typeTag == ATypeTag.FLOAT) {
+ float value = AFloatSerializerDeserializer.getFloat(bytes,
startOffset);
+
+ // Greater than long max value or has a decimal value that is not 0
+ if (value > Long.MAX_VALUE || value > Math.floor(value)) {
+ return true;
+ }
+ }
+
+ // Double check (1.0, 2.0 are fine, but 1.5 is not)
+ if (typeTag == ATypeTag.DOUBLE) {
+ double value = ADoubleSerializerDeserializer.getDouble(bytes,
startOffset);
+
+ // Greater than long max value or has a decimal value that is not 0
+ if (value > Long.MAX_VALUE || value > Math.floor(value)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * This method returns the long value of the provided number.
+ *
+ * @param bytes data bytes
+ * @param startOffset start offset
+ * @param typeTag ATypeTag of the value
+ *
+ * @return the long value of the provided number
+ */
+ private long getLongValue(byte[] bytes, int startOffset, ATypeTag typeTag,
int argIndex)
+ throws HyracksDataException {
+ switch (typeTag) {
+ case TINYINT:
+ return AInt8SerializerDeserializer.getByte(bytes, startOffset);
+ case SMALLINT:
+ return AInt16SerializerDeserializer.getShort(bytes,
startOffset);
+ case INTEGER:
+ return AInt32SerializerDeserializer.getInt(bytes, startOffset);
+ case BIGINT:
+ return AInt64SerializerDeserializer.getLong(bytes,
startOffset);
+ case FLOAT:
+ return (long) AFloatSerializerDeserializer.getFloat(bytes,
startOffset);
+ case DOUBLE:
+ return (long) ADoubleSerializerDeserializer.getDouble(bytes,
startOffset);
+ default:
+ throw new TypeMismatchException(sourceLoc, functionIdentifier,
argIndex, typeTag.serialize(),
+ ATypeTag.TINYINT.serialize(),
ATypeTag.SMALLINT.serialize(), ATypeTag.INTEGER.serialize(),
+ ATypeTag.BIGINT.serialize(),
ATypeTag.FLOAT.serialize(), ATypeTag.DOUBLE.serialize());
+ }
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitAndDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitAndDescriptor.java
new file mode 100644
index 0000000..5d5a278
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitAndDescriptor.java
@@ -0,0 +1,53 @@
+/*
+ * 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.bitwise;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+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.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class BitAndDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ public static final IFunctionDescriptorFactory FACTORY =
BitAndDescriptor::new;
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.BIT_AND;
+ }
+
+ @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 {
+ return new BitAndEvaluator(ctx, args, getIdentifier(),
sourceLoc);
+ }
+ };
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitAndEvaluator.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitAndEvaluator.java
new file mode 100644
index 0000000..e6b91bd
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitAndEvaluator.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.bitwise;
+
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+
+public class BitAndEvaluator extends AbstractBitwiseEvaluator {
+
+ BitAndEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory[]
argEvaluatorFactories,
+ FunctionIdentifier functionIdentifier, SourceLocation
sourceLocation) throws HyracksDataException {
+ super(context, argEvaluatorFactories, functionIdentifier,
sourceLocation);
+ }
+
+ // AND bitwise operation
+ protected long applyBitwiseOperation(long value1, long value2) {
+ return value1 & value2;
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitOrDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitOrDescriptor.java
new file mode 100644
index 0000000..3f9872d
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitOrDescriptor.java
@@ -0,0 +1,53 @@
+/*
+ * 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.bitwise;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+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.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class BitOrDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ public static final IFunctionDescriptorFactory FACTORY =
BitOrDescriptor::new;
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.BIT_OR;
+ }
+
+ @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 {
+ return new BitOrEvaluator(ctx, args, getIdentifier(),
sourceLoc);
+ }
+ };
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitOrEvaluator.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitOrEvaluator.java
new file mode 100644
index 0000000..d08f5fc
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitOrEvaluator.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.bitwise;
+
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+
+public class BitOrEvaluator extends AbstractBitwiseEvaluator {
+
+ BitOrEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory[]
argEvaluatorFactories,
+ FunctionIdentifier functionIdentifier, SourceLocation
sourceLocation) throws HyracksDataException {
+ super(context, argEvaluatorFactories, functionIdentifier,
sourceLocation);
+ }
+
+ // OR bitwise operation
+ protected long applyBitwiseOperation(long value1, long value2) {
+ return value1 | value2;
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitXorDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitXorDescriptor.java
new file mode 100644
index 0000000..86234dd
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitXorDescriptor.java
@@ -0,0 +1,53 @@
+/*
+ * 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.bitwise;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+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.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class BitXorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ public static final IFunctionDescriptorFactory FACTORY =
BitXorDescriptor::new;
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.BIT_XOR;
+ }
+
+ @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 {
+ return new BitXorEvaluator(ctx, args, getIdentifier(),
sourceLoc);
+ }
+ };
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitXorEvaluator.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitXorEvaluator.java
new file mode 100644
index 0000000..67cc9cf
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/bitwise/BitXorEvaluator.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.bitwise;
+
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+
+public class BitXorEvaluator extends AbstractBitwiseEvaluator {
+
+ BitXorEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory[]
argEvaluatorFactories,
+ FunctionIdentifier functionIdentifier, SourceLocation
sourceLocation) throws HyracksDataException {
+ super(context, argEvaluatorFactories, functionIdentifier,
sourceLocation);
+ }
+
+ // XOR bitwise operation
+ protected long applyBitwiseOperation(long value1, long value2) {
+ return value1 ^ value2;
+ }
+}
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 6269582..ebee10a 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
@@ -440,6 +440,9 @@
import
org.apache.asterix.runtime.evaluators.functions.binary.PrintBinaryDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.binary.SubBinaryFromDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.binary.SubBinaryFromToDescriptor;
+import
org.apache.asterix.runtime.evaluators.functions.bitwise.BitAndDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.bitwise.BitOrDescriptor;
+import
org.apache.asterix.runtime.evaluators.functions.bitwise.BitXorDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByIndexDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByNameDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.records.FieldAccessNestedDescriptor;
@@ -914,6 +917,11 @@
fc.add(FindBinaryDescriptor.FACTORY);
fc.add(FindBinaryFromDescriptor.FACTORY);
+ // Bitwise functions
+ fc.add(BitAndDescriptor.FACTORY);
+ fc.add(BitOrDescriptor.FACTORY);
+ fc.add(BitXorDescriptor.FACTORY);
+
// String functions
fc.add(StringLikeDescriptor.FACTORY);
fc.add(StringContainsDescriptor.FACTORY);
--
To view, visit https://asterix-gerrit.ics.uci.edu/3377
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I70a6376d6ca12da55eeff88fa0b1c85f970ef8e6
Gerrit-Change-Number: 3377
Gerrit-PatchSet: 1
Gerrit-Owner: Hussain Towaileb <[email protected]>