http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlSerializerDeserializerProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlSerializerDeserializerProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlSerializerDeserializerProvider.java deleted file mode 100644 index ae2dea6..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlSerializerDeserializerProvider.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.asterix.formats.nontagged; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.Serializable; - -import org.apache.asterix.dataflow.data.nontagged.serde.ABinarySerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ACircleSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ADayTimeDurationSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer; -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.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ALineSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.AMissingSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ANullSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.AObjectSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.APoint3DSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.APolygonSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ARectangleSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.AStringSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.AUUIDSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.AUnorderedListSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.AYearMonthDurationSerializerDeserializer; -import org.apache.asterix.dataflow.data.nontagged.serde.SerializerDeserializerUtil; -import org.apache.asterix.om.base.AMissing; -import org.apache.asterix.om.base.ANull; -import org.apache.asterix.om.base.IAObject; -import org.apache.asterix.om.types.AOrderedListType; -import org.apache.asterix.om.types.ARecordType; -import org.apache.asterix.om.types.ATypeTag; -import org.apache.asterix.om.types.AUnorderedListType; -import org.apache.asterix.om.types.IAType; -import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException; -import org.apache.hyracks.algebricks.data.ISerializerDeserializerProvider; -import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; -import org.apache.hyracks.api.exceptions.HyracksDataException; -import org.apache.hyracks.dataflow.common.data.marshalling.ShortSerializerDeserializer; -import org.apache.hyracks.util.string.UTF8StringReader; -import org.apache.hyracks.util.string.UTF8StringWriter; - -public class AqlSerializerDeserializerProvider implements ISerializerDeserializerProvider, Serializable { - - private static final long serialVersionUID = 1L; - public static final AqlSerializerDeserializerProvider INSTANCE = new AqlSerializerDeserializerProvider(); - - private AqlSerializerDeserializerProvider() { - } - - // Can't be shared among threads <Stateful> - @SuppressWarnings("rawtypes") - public ISerializerDeserializer getAStringSerializerDeserializer() { - return addTag(new AStringSerializerDeserializer(new UTF8StringWriter(), new UTF8StringReader()), - ATypeTag.STRING); - } - - @SuppressWarnings("rawtypes") - @Override - public ISerializerDeserializer getSerializerDeserializer(Object typeInfo) { - IAType aqlType = (IAType) typeInfo; - if (aqlType == null) { - return null; - } - switch (aqlType.getTypeTag()) { - case ANY: - case UNION: - // we could do smth better for nullable fields - return AObjectSerializerDeserializer.INSTANCE; - default: - return addTag(getNonTaggedSerializerDeserializer(aqlType), aqlType.getTypeTag()); - } - } - - @SuppressWarnings("rawtypes") - public ISerializerDeserializer getNonTaggedSerializerDeserializer(IAType aqlType) { - switch (aqlType.getTypeTag()) { - case CIRCLE: - return ACircleSerializerDeserializer.INSTANCE; - case DATE: - return ADateSerializerDeserializer.INSTANCE; - case DATETIME: - return ADateTimeSerializerDeserializer.INSTANCE; - case DOUBLE: - return ADoubleSerializerDeserializer.INSTANCE; - case FLOAT: - return AFloatSerializerDeserializer.INSTANCE; - case BOOLEAN: - return ABooleanSerializerDeserializer.INSTANCE; - case INT8: - return AInt8SerializerDeserializer.INSTANCE; - case INT16: - return AInt16SerializerDeserializer.INSTANCE; - case INT32: - return AInt32SerializerDeserializer.INSTANCE; - case INT64: - return AInt64SerializerDeserializer.INSTANCE; - case LINE: - return ALineSerializerDeserializer.INSTANCE; - case MISSING: - return AMissingSerializerDeserializer.INSTANCE; - case NULL: - return ANullSerializerDeserializer.INSTANCE; - case STRING: - return AStringSerializerDeserializer.INSTANCE; - case BINARY: - return ABinarySerializerDeserializer.INSTANCE; - case TIME: - return ATimeSerializerDeserializer.INSTANCE; - case DURATION: - return ADurationSerializerDeserializer.INSTANCE; - case YEARMONTHDURATION: - return AYearMonthDurationSerializerDeserializer.INSTANCE; - case DAYTIMEDURATION: - return ADayTimeDurationSerializerDeserializer.INSTANCE; - case INTERVAL: - return AIntervalSerializerDeserializer.INSTANCE; - case ORDEREDLIST: - return new AOrderedListSerializerDeserializer((AOrderedListType) aqlType); - case POINT: - return APointSerializerDeserializer.INSTANCE; - case POINT3D: - return APoint3DSerializerDeserializer.INSTANCE; - case RECTANGLE: - return ARectangleSerializerDeserializer.INSTANCE; - case POLYGON: - return APolygonSerializerDeserializer.INSTANCE; - case RECORD: - return new ARecordSerializerDeserializer((ARecordType) aqlType); - case UNORDEREDLIST: - return new AUnorderedListSerializerDeserializer((AUnorderedListType) aqlType); - case UUID: - return AUUIDSerializerDeserializer.INSTANCE; - case SHORTWITHOUTTYPEINFO: - return ShortSerializerDeserializer.INSTANCE; - default: - throw new NotImplementedException( - "No serializer/deserializer implemented for type " + aqlType.getTypeTag() + " ."); - } - } - - @SuppressWarnings("rawtypes") - private ISerializerDeserializer addTag(final ISerializerDeserializer nonTaggedSerde, final ATypeTag typeTag) { - return new ISerializerDeserializer<IAObject>() { - - private static final long serialVersionUID = 1L; - - @Override - public IAObject deserialize(DataInput in) throws HyracksDataException { - try { - ATypeTag tag = SerializerDeserializerUtil.deserializeTag(in); - //deserialize the tag (move input cursor forward) and check if it's not NULL tag - if (tag == ATypeTag.MISSING) { - return AMissing.MISSING; - } - if (tag == ATypeTag.NULL) { - return ANull.NULL; - } - } catch (IOException e) { - throw new HyracksDataException(e); - } - return (IAObject) nonTaggedSerde.deserialize(in); - } - - @SuppressWarnings("unchecked") - @Override - public void serialize(IAObject instance, DataOutput out) throws HyracksDataException { - SerializerDeserializerUtil.serializeTag(instance, out); - nonTaggedSerde.serialize(instance, out); - } - }; - } -}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlTypeTraitProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlTypeTraitProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlTypeTraitProvider.java deleted file mode 100644 index 129f14b..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/AqlTypeTraitProvider.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.asterix.formats.nontagged; - -import org.apache.asterix.om.types.IAType; -import org.apache.hyracks.algebricks.data.ITypeTraitProvider; -import org.apache.hyracks.api.dataflow.value.ITypeTraits; - -public class AqlTypeTraitProvider implements ITypeTraitProvider { - - // WARNING: the byte sizes depend on the serializer! - // currently assuming a serializer that adds a 1-byte type indicator before - // the data - private static final ITypeTraits ONEBYTETYPETRAIT = new TypeTrait(1 + 1); - private static final ITypeTraits TWOBYTETYPETRAIT = new TypeTrait(2 + 1); - private static final ITypeTraits FOURBYTETYPETRAIT = new TypeTrait(4 + 1); - private static final ITypeTraits EIGHTBYTETYPETRAIT = new TypeTrait(8 + 1); - private static final ITypeTraits SIXTEENBYTETYPETRAIT = new TypeTrait(16 + 1); - private static final ITypeTraits SEVENTEENBYTETYPETRAIT = new TypeTrait(17 + 1); - private static final ITypeTraits THIRTYTWOBYTETYPETRAIT = new TypeTrait(32 + 1); - private static final ITypeTraits TWENTYFOURBYTETYPETRAIT = new TypeTrait(24 + 1); - - private static final ITypeTraits VARLENTYPETRAIT = new TypeTrait(false, -1); - - public static final AqlTypeTraitProvider INSTANCE = new AqlTypeTraitProvider(); - - @Override - public ITypeTraits getTypeTrait(Object type) { - IAType aqlType = (IAType) type; - if (aqlType == null) { - return null; - } - switch (aqlType.getTypeTag()) { - case BOOLEAN: - case INT8: - return ONEBYTETYPETRAIT; - case INT16: - return TWOBYTETYPETRAIT; - case INT32: - case FLOAT: - case DATE: - case TIME: - return FOURBYTETYPETRAIT; - case INT64: - case DOUBLE: - case DATETIME: - case DURATION: - return EIGHTBYTETYPETRAIT; - case POINT: - case UUID: - return SIXTEENBYTETYPETRAIT; - case INTERVAL: - return SEVENTEENBYTETYPETRAIT; - case POINT3D: - return TWENTYFOURBYTETYPETRAIT; - case LINE: - return THIRTYTWOBYTETYPETRAIT; - default: { - return VARLENTYPETRAIT; - } - } - } -} - -class TypeTrait implements ITypeTraits { - private static final long serialVersionUID = 1L; - - @Override - public boolean isFixedLength() { - return isFixedLength; - } - - @Override - public int getFixedLength() { - return fixedLength; - } - - private boolean isFixedLength; - private int fixedLength; - - public TypeTrait(boolean isFixedLength, int fixedLength) { - this.isFixedLength = isFixedLength; - this.fixedLength = fixedLength; - } - - public TypeTrait(int fixedLength) { - this.isFixedLength = true; - this.fixedLength = fixedLength; - } -} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryBooleanInspector.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryBooleanInspector.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryBooleanInspector.java new file mode 100644 index 0000000..fd4df0d --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryBooleanInspector.java @@ -0,0 +1,57 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.EnumDeserializer; +import org.apache.hyracks.algebricks.data.IBinaryBooleanInspector; +import org.apache.hyracks.algebricks.data.IBinaryBooleanInspectorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; + +public class BinaryBooleanInspector implements IBinaryBooleanInspector { + private static final BinaryBooleanInspector INSTANCE = new BinaryBooleanInspector(); + public static final IBinaryBooleanInspectorFactory FACTORY = new IBinaryBooleanInspectorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IBinaryBooleanInspector createBinaryBooleanInspector(IHyracksTaskContext ctx) { + // Stateless class. No need to construct an object per call + return INSTANCE; + } + }; + + private BinaryBooleanInspector() { + } + + @Override + public boolean getBooleanValue(byte[] bytes, int offset, int length) { + byte serializedTypeTag = bytes[offset]; + if (serializedTypeTag == ATypeTag.SERIALIZED_MISSING_TYPE_TAG + || serializedTypeTag == ATypeTag.SERIALIZED_NULL_TYPE_TAG) { + return false; + } + /** check if the runtime type is boolean */ + ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serializedTypeTag); + if (typeTag != ATypeTag.BOOLEAN) { + throw new IllegalStateException("Runtime error: the select condition should be of the boolean type!"); + } + return bytes[offset + 1] == 1; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryComparatorFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryComparatorFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryComparatorFactoryProvider.java new file mode 100644 index 0000000..4e0e210 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryComparatorFactoryProvider.java @@ -0,0 +1,220 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.dataflow.data.nontagged.comparators.ABinaryComparator; +import org.apache.asterix.dataflow.data.nontagged.comparators.ACirclePartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.ADurationPartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.AIntervalAscPartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.AIntervalDescPartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.ALinePartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.AObjectAscBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.AObjectDescBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.APoint3DPartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.APointPartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.APolygonPartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.ARectanglePartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.AUUIDPartialBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.BooleanBinaryComparatorFactory; +import org.apache.asterix.dataflow.data.nontagged.comparators.RawBinaryComparatorFactory; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.data.IBinaryComparatorFactoryProvider; +import org.apache.hyracks.api.dataflow.value.IBinaryComparator; +import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory; +import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.data.std.accessors.PointableBinaryComparatorFactory; +import org.apache.hyracks.data.std.primitive.ByteArrayPointable; +import org.apache.hyracks.data.std.primitive.BytePointable; +import org.apache.hyracks.data.std.primitive.DoublePointable; +import org.apache.hyracks.data.std.primitive.FloatPointable; +import org.apache.hyracks.data.std.primitive.IntegerPointable; +import org.apache.hyracks.data.std.primitive.LongPointable; +import org.apache.hyracks.data.std.primitive.ShortPointable; +import org.apache.hyracks.data.std.primitive.UTF8StringLowercasePointable; +import org.apache.hyracks.data.std.primitive.UTF8StringPointable; + +import java.io.Serializable; + +public class BinaryComparatorFactoryProvider implements IBinaryComparatorFactoryProvider, Serializable { + + private static final long serialVersionUID = 1L; + public static final BinaryComparatorFactoryProvider INSTANCE = new BinaryComparatorFactoryProvider(); + public static final PointableBinaryComparatorFactory BYTE_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(BytePointable.FACTORY); + public static final PointableBinaryComparatorFactory SHORT_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(ShortPointable.FACTORY); + public static final PointableBinaryComparatorFactory INTEGER_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(IntegerPointable.FACTORY); + public static final PointableBinaryComparatorFactory LONG_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(LongPointable.FACTORY); + public static final PointableBinaryComparatorFactory FLOAT_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(FloatPointable.FACTORY); + public static final PointableBinaryComparatorFactory DOUBLE_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(DoublePointable.FACTORY); + public static final PointableBinaryComparatorFactory UTF8STRING_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(UTF8StringPointable.FACTORY); + // Equivalent to UTF8STRING_POINTABLE_INSTANCE but all characters are considered lower case to implement + // case-insensitive comparisons. + public static final PointableBinaryComparatorFactory UTF8STRING_LOWERCASE_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(UTF8StringLowercasePointable.FACTORY); + public static final PointableBinaryComparatorFactory BINARY_POINTABLE_INSTANCE = + new PointableBinaryComparatorFactory(ByteArrayPointable.FACTORY); + + private BinaryComparatorFactoryProvider() { + } + + // This method add the option of ignoring the case in string comparisons. + // TODO: We should incorporate this option more nicely, but I'd have to change algebricks. + public IBinaryComparatorFactory getBinaryComparatorFactory(Object type, boolean ascending, boolean ignoreCase) { + if (type == null) { + return anyBinaryComparatorFactory(ascending); + } + IAType aqlType = (IAType) type; + if (aqlType.getTypeTag() == ATypeTag.STRING && ignoreCase) { + return addOffset(UTF8STRING_LOWERCASE_POINTABLE_INSTANCE, ascending); + } + return getBinaryComparatorFactory(type, ascending); + } + + @Override + public IBinaryComparatorFactory getBinaryComparatorFactory(Object type, boolean ascending) { + // During a comparison, since proper type promotion among several numeric types are required, + // we will use AObjectAscBinaryComparatorFactory, instead of using a specific comparator + return anyBinaryComparatorFactory(ascending); + } + + public IBinaryComparatorFactory getBinaryComparatorFactory(ATypeTag type, boolean ascending) { + switch (type) { + case ANY: + case UNION: + // we could do smth better for nullable fields + return anyBinaryComparatorFactory(ascending); + case NULL: + case MISSING: + return new IBinaryComparatorFactory() { + + private static final long serialVersionUID = 1L; + + @Override + public IBinaryComparator createBinaryComparator() { + return new IBinaryComparator() { + + @Override + public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { + return 0; + } + }; + } + }; + case BOOLEAN: + return addOffset(BooleanBinaryComparatorFactory.INSTANCE, ascending); + case INT8: + return addOffset(BYTE_POINTABLE_INSTANCE, ascending); + case INT16: + return addOffset(SHORT_POINTABLE_INSTANCE, ascending); + case DATE: + case TIME: + case YEARMONTHDURATION: + case INT32: + return addOffset(INTEGER_POINTABLE_INSTANCE, ascending); + case DATETIME: + case DAYTIMEDURATION: + case INT64: + return addOffset(LONG_POINTABLE_INSTANCE, ascending); + case FLOAT: + return addOffset(FLOAT_POINTABLE_INSTANCE, ascending); + case DOUBLE: + return addOffset(DOUBLE_POINTABLE_INSTANCE, ascending); + case STRING: + return addOffset(UTF8STRING_POINTABLE_INSTANCE, ascending); + case RECTANGLE: + return addOffset(ARectanglePartialBinaryComparatorFactory.INSTANCE, ascending); + case CIRCLE: + return addOffset(ACirclePartialBinaryComparatorFactory.INSTANCE, ascending); + case POINT: + return addOffset(APointPartialBinaryComparatorFactory.INSTANCE, ascending); + case POINT3D: + return addOffset(APoint3DPartialBinaryComparatorFactory.INSTANCE, ascending); + case LINE: + return addOffset(ALinePartialBinaryComparatorFactory.INSTANCE, ascending); + case POLYGON: + return addOffset(APolygonPartialBinaryComparatorFactory.INSTANCE, ascending); + case DURATION: + return addOffset(ADurationPartialBinaryComparatorFactory.INSTANCE, ascending); + case INTERVAL: + return addOffset(intervalBinaryComparatorFactory(ascending), ascending); + case UUID: + return addOffset(AUUIDPartialBinaryComparatorFactory.INSTANCE, ascending); + case BINARY: + return addOffset(BINARY_POINTABLE_INSTANCE, ascending); + default: + return addOffset(RawBinaryComparatorFactory.INSTANCE, ascending); + } + } + + private IBinaryComparatorFactory addOffset(final IBinaryComparatorFactory inst, final boolean ascending) { + return new IBinaryComparatorFactory() { + + private static final long serialVersionUID = 1L; + + @Override + public IBinaryComparator createBinaryComparator() { + final IBinaryComparator bc = inst.createBinaryComparator(); + if (ascending) { + return new ABinaryComparator() { + + @Override + public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) + throws HyracksDataException { + return bc.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1); + } + }; + } else { + return new ABinaryComparator() { + @Override + public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) + throws HyracksDataException { + return -bc.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1); + } + }; + } + } + }; + } + + private IBinaryComparatorFactory anyBinaryComparatorFactory(boolean ascending) { + if (ascending) { + return AObjectAscBinaryComparatorFactory.INSTANCE; + } else { + return AObjectDescBinaryComparatorFactory.INSTANCE; + } + } + + private IBinaryComparatorFactory intervalBinaryComparatorFactory(boolean ascending) { + // Intervals have separate binary comparator factories, since asc is primarily based on start point + // and desc is similarly based on end point. + if (ascending) { + return AIntervalAscPartialBinaryComparatorFactory.INSTANCE; + } else { + return AIntervalDescPartialBinaryComparatorFactory.INSTANCE; + } + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryHashFunctionFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryHashFunctionFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryHashFunctionFactoryProvider.java new file mode 100644 index 0000000..cea0369 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryHashFunctionFactoryProvider.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.formats.nontagged; + +import java.io.Serializable; + +import org.apache.asterix.dataflow.data.nontagged.hash.AMurmurHash3BinaryHashFunctionFamily; +import org.apache.hyracks.algebricks.data.IBinaryHashFunctionFactoryProvider; +import org.apache.hyracks.api.dataflow.value.IBinaryHashFunction; +import org.apache.hyracks.api.dataflow.value.IBinaryHashFunctionFactory; +import org.apache.hyracks.data.std.accessors.PointableBinaryHashFunctionFactory; +import org.apache.hyracks.data.std.primitive.DoublePointable; +import org.apache.hyracks.data.std.primitive.FloatPointable; +import org.apache.hyracks.data.std.primitive.IntegerPointable; +import org.apache.hyracks.data.std.primitive.UTF8StringLowercasePointable; +import org.apache.hyracks.data.std.primitive.UTF8StringPointable; + +public class BinaryHashFunctionFactoryProvider implements IBinaryHashFunctionFactoryProvider, Serializable { + + private static final long serialVersionUID = 1L; + public static final BinaryHashFunctionFactoryProvider INSTANCE = new BinaryHashFunctionFactoryProvider(); + public static final PointableBinaryHashFunctionFactory INTEGER_POINTABLE_INSTANCE = + new PointableBinaryHashFunctionFactory(IntegerPointable.FACTORY); + public static final PointableBinaryHashFunctionFactory FLOAT_POINTABLE_INSTANCE = + new PointableBinaryHashFunctionFactory(FloatPointable.FACTORY); + public static final PointableBinaryHashFunctionFactory DOUBLE_POINTABLE_INSTANCE = + new PointableBinaryHashFunctionFactory(DoublePointable.FACTORY); + public static final PointableBinaryHashFunctionFactory UTF8STRING_POINTABLE_INSTANCE = + new PointableBinaryHashFunctionFactory(UTF8StringPointable.FACTORY); + // Equivalent to UTF8STRING_POINTABLE_INSTANCE but all characters are considered lower case to implement + // case-insensitive hashing. + public static final PointableBinaryHashFunctionFactory UTF8STRING_LOWERCASE_POINTABLE_INSTANCE = + new PointableBinaryHashFunctionFactory(UTF8StringLowercasePointable.FACTORY); + + private BinaryHashFunctionFactoryProvider() { + } + + @Override + public IBinaryHashFunctionFactory getBinaryHashFunctionFactory(Object type) { + return new IBinaryHashFunctionFactory() { + + private static final long serialVersionUID = 1L; + + @Override + public IBinaryHashFunction createBinaryHashFunction() { + // Actual numeric type promotion happens in the createBinaryHashFunction() + return AMurmurHash3BinaryHashFunctionFamily.INSTANCE.createBinaryHashFunction(0); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryHashFunctionFamilyProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryHashFunctionFamilyProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryHashFunctionFamilyProvider.java new file mode 100644 index 0000000..35d9316 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryHashFunctionFamilyProvider.java @@ -0,0 +1,48 @@ +/* + * 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.formats.nontagged; + +import java.io.Serializable; + +import org.apache.asterix.dataflow.data.nontagged.hash.AMurmurHash3BinaryHashFunctionFamily; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.data.IBinaryHashFunctionFamilyProvider; +import org.apache.hyracks.api.dataflow.value.IBinaryHashFunctionFamily; + +/** + * We use a binary hash function that promotes numeric types (INT8,INT16,INT32,INT64,FLOAT) to DOUBLE if requested. + * Non-numeric types will be hashed without type promotion. + */ +public class BinaryHashFunctionFamilyProvider implements IBinaryHashFunctionFamilyProvider, Serializable { + + private static final long serialVersionUID = 1L; + public static final BinaryHashFunctionFamilyProvider INSTANCE = new BinaryHashFunctionFamilyProvider(); + + private BinaryHashFunctionFamilyProvider() { + + } + + @Override + public IBinaryHashFunctionFamily getBinaryHashFunctionFamily(Object type) throws AlgebricksException { + // AMurmurHash3BinaryHashFunctionFamily converts numeric type to double type before doing hash() + return AMurmurHash3BinaryHashFunctionFamily.INSTANCE; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryIntegerInspector.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryIntegerInspector.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryIntegerInspector.java new file mode 100644 index 0000000..4e108e3 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryIntegerInspector.java @@ -0,0 +1,45 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.om.types.hierachy.ATypeHierarchy; +import org.apache.hyracks.algebricks.data.IBinaryIntegerInspector; +import org.apache.hyracks.algebricks.data.IBinaryIntegerInspectorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class BinaryIntegerInspector implements IBinaryIntegerInspector { + + public static final IBinaryIntegerInspectorFactory FACTORY = new IBinaryIntegerInspectorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IBinaryIntegerInspector createBinaryIntegerInspector(IHyracksTaskContext ctx) { + return new BinaryIntegerInspector(); + } + }; + + private BinaryIntegerInspector() { + } + + @Override + public int getIntegerValue(byte[] bytes, int offset, int length) throws HyracksDataException { + return ATypeHierarchy.getIntegerValue("integer-inspector", 0, bytes, offset); + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryTokenizerFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryTokenizerFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryTokenizerFactoryProvider.java new file mode 100644 index 0000000..58740ee --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/BinaryTokenizerFactoryProvider.java @@ -0,0 +1,85 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.dataflow.data.common.AListElementTokenFactory; +import org.apache.asterix.dataflow.data.common.AOrderedListBinaryTokenizerFactory; +import org.apache.asterix.dataflow.data.common.AUnorderedListBinaryTokenizerFactory; +import org.apache.asterix.dataflow.data.common.IBinaryTokenizerFactoryProvider; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.DelimitedUTF8StringBinaryTokenizerFactory; +import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.HashedUTF8WordTokenFactory; +import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.IBinaryTokenizerFactory; +import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.NGramUTF8StringBinaryTokenizerFactory; +import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.UTF8NGramTokenFactory; +import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.UTF8WordTokenFactory; + +public class BinaryTokenizerFactoryProvider implements IBinaryTokenizerFactoryProvider { + + public static final BinaryTokenizerFactoryProvider INSTANCE = new BinaryTokenizerFactoryProvider(); + + private static final IBinaryTokenizerFactory aqlStringTokenizer = + new DelimitedUTF8StringBinaryTokenizerFactory(true, true, + new UTF8WordTokenFactory(ATypeTag.SERIALIZED_STRING_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG)); + + private static final IBinaryTokenizerFactory aqlHashingStringTokenizer = + new DelimitedUTF8StringBinaryTokenizerFactory(true, true, + new HashedUTF8WordTokenFactory(ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG)); + + private static final IBinaryTokenizerFactory orderedListTokenizer = new AOrderedListBinaryTokenizerFactory( + new AListElementTokenFactory()); + + private static final IBinaryTokenizerFactory unorderedListTokenizer = new AUnorderedListBinaryTokenizerFactory( + new AListElementTokenFactory()); + + @Override + public IBinaryTokenizerFactory getWordTokenizerFactory(ATypeTag typeTag, boolean hashedTokens) { + switch (typeTag) { + case STRING: + return hashedTokens ? aqlHashingStringTokenizer : aqlStringTokenizer; + case ORDEREDLIST: + return orderedListTokenizer; + case UNORDEREDLIST: + return unorderedListTokenizer; + default: + return null; + } + } + + @Override + public IBinaryTokenizerFactory getNGramTokenizerFactory(ATypeTag typeTag, int gramLength, boolean usePrePost, + boolean hashedTokens) { + switch (typeTag) { + case STRING: + if (hashedTokens) { + return null; + } else { + return new NGramUTF8StringBinaryTokenizerFactory(gramLength, usePrePost, true, true, + new UTF8NGramTokenFactory(ATypeTag.SERIALIZED_STRING_TYPE_TAG, + ATypeTag.SERIALIZED_INT32_TYPE_TAG)); + } + case ORDEREDLIST: + return orderedListTokenizer; + case UNORDEREDLIST: + return unorderedListTokenizer; + default: + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/CSVPrinterFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/CSVPrinterFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/CSVPrinterFactoryProvider.java new file mode 100644 index 0000000..e510442 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/CSVPrinterFactoryProvider.java @@ -0,0 +1,148 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ABooleanPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ACirclePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADatePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADateTimePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADayTimeDurationPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADoublePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ADurationPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AFloatPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AInt16PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AInt32PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AInt64PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AInt8PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AIntervalPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ALinePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ANullPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AOptionalFieldPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AObjectPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.APoint3DPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.APointPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.APolygonPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ARecordPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ARectanglePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AStringPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.ATimePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AUnionPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.csv.AYearMonthDurationPrinterFactory; +import org.apache.asterix.om.types.ARecordType; +import org.apache.asterix.om.types.AUnionType; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException; +import org.apache.hyracks.algebricks.data.IPrinterFactory; +import org.apache.hyracks.algebricks.data.IPrinterFactoryProvider; + +public class CSVPrinterFactoryProvider implements IPrinterFactoryProvider { + + public static final CSVPrinterFactoryProvider INSTANCE = new CSVPrinterFactoryProvider(); + + private CSVPrinterFactoryProvider() { + } + + @Override + public IPrinterFactory getPrinterFactory(Object type) { + IAType aqlType = (IAType) type; + + if (aqlType != null) { + switch (aqlType.getTypeTag()) { + case INT8: + return AInt8PrinterFactory.INSTANCE; + case INT16: + return AInt16PrinterFactory.INSTANCE; + case INT32: + return AInt32PrinterFactory.INSTANCE; + case INT64: + return AInt64PrinterFactory.INSTANCE; + case MISSING: + case NULL: + return ANullPrinterFactory.INSTANCE; + case BOOLEAN: + return ABooleanPrinterFactory.INSTANCE; + case FLOAT: + return AFloatPrinterFactory.INSTANCE; + case DOUBLE: + return ADoublePrinterFactory.INSTANCE; + case TIME: + return ATimePrinterFactory.INSTANCE; + case DATE: + return ADatePrinterFactory.INSTANCE; + case DATETIME: + return ADateTimePrinterFactory.INSTANCE; + case DURATION: + return ADurationPrinterFactory.INSTANCE; + case YEARMONTHDURATION: + return AYearMonthDurationPrinterFactory.INSTANCE; + case DAYTIMEDURATION: + return ADayTimeDurationPrinterFactory.INSTANCE; + case INTERVAL: + return AIntervalPrinterFactory.INSTANCE; + case POINT: + return APointPrinterFactory.INSTANCE; + case POINT3D: + return APoint3DPrinterFactory.INSTANCE; + case LINE: + return ALinePrinterFactory.INSTANCE; + case POLYGON: + return APolygonPrinterFactory.INSTANCE; + case CIRCLE: + return ACirclePrinterFactory.INSTANCE; + case RECTANGLE: + return ARectanglePrinterFactory.INSTANCE; + case STRING: + return AStringPrinterFactory.INSTANCE; + case RECORD: + return new ARecordPrinterFactory((ARecordType) aqlType); + case ORDEREDLIST: + throw new NotImplementedException("'Orderedlist' type unsupported for CSV output"); + case UNORDEREDLIST: + throw new NotImplementedException("'Unorderedlist' type unsupported for CSV output"); + case UNION: + if (((AUnionType) aqlType).isUnknownableType()) { + return new AOptionalFieldPrinterFactory((AUnionType) aqlType); + } else { + return new AUnionPrinterFactory((AUnionType) aqlType); + } + case UUID: + return AUUIDPrinterFactory.INSTANCE; + case SHORTWITHOUTTYPEINFO: + return ShortWithoutTypeInfoPrinterFactory.INSTANCE; + case ANY: + case BINARY: + case BITARRAY: + case ENUM: + case SPARSERECORD: + case SYSTEM_NULL: + case TYPE: + case UINT16: + case UINT32: + case UINT64: + case UINT8: + // These types are not intended to be printed to the user. + break; + } + } + return AObjectPrinterFactory.INSTANCE; + + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/CleanJSONPrinterFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/CleanJSONPrinterFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/CleanJSONPrinterFactoryProvider.java new file mode 100644 index 0000000..03fa666 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/CleanJSONPrinterFactoryProvider.java @@ -0,0 +1,152 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ABinaryHexPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ABooleanPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ACirclePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADatePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADateTimePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADayTimeDurationPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADoublePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ADurationPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AFloatPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt16PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt32PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt64PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt8PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AIntervalPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ALinePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ANullPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AOptionalFieldPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AObjectPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AOrderedlistPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.APoint3DPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.APointPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.APolygonPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ARecordPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ARectanglePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AStringPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ATimePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AUnionPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AUnorderedlistPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AYearMonthDurationPrinterFactory; +import org.apache.asterix.om.types.AOrderedListType; +import org.apache.asterix.om.types.ARecordType; +import org.apache.asterix.om.types.AUnionType; +import org.apache.asterix.om.types.AUnorderedListType; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.data.IPrinterFactory; +import org.apache.hyracks.algebricks.data.IPrinterFactoryProvider; + +public class CleanJSONPrinterFactoryProvider implements IPrinterFactoryProvider { + + public static final CleanJSONPrinterFactoryProvider INSTANCE = new CleanJSONPrinterFactoryProvider(); + + private CleanJSONPrinterFactoryProvider() { + } + + @Override + public IPrinterFactory getPrinterFactory(Object type) { + IAType aqlType = (IAType) type; + + if (aqlType != null) { + switch (aqlType.getTypeTag()) { + case INT8: + return AInt8PrinterFactory.INSTANCE; + case INT16: + return AInt16PrinterFactory.INSTANCE; + case INT32: + return AInt32PrinterFactory.INSTANCE; + case INT64: + return AInt64PrinterFactory.INSTANCE; + case MISSING: + case NULL: + return ANullPrinterFactory.INSTANCE; + case BOOLEAN: + return ABooleanPrinterFactory.INSTANCE; + case FLOAT: + return AFloatPrinterFactory.INSTANCE; + case DOUBLE: + return ADoublePrinterFactory.INSTANCE; + case TIME: + return ATimePrinterFactory.INSTANCE; + case DATE: + return ADatePrinterFactory.INSTANCE; + case DATETIME: + return ADateTimePrinterFactory.INSTANCE; + case DURATION: + return ADurationPrinterFactory.INSTANCE; + case YEARMONTHDURATION: + return AYearMonthDurationPrinterFactory.INSTANCE; + case DAYTIMEDURATION: + return ADayTimeDurationPrinterFactory.INSTANCE; + case INTERVAL: + return AIntervalPrinterFactory.INSTANCE; + case POINT: + return APointPrinterFactory.INSTANCE; + case POINT3D: + return APoint3DPrinterFactory.INSTANCE; + case LINE: + return ALinePrinterFactory.INSTANCE; + case POLYGON: + return APolygonPrinterFactory.INSTANCE; + case CIRCLE: + return ACirclePrinterFactory.INSTANCE; + case RECTANGLE: + return ARectanglePrinterFactory.INSTANCE; + case STRING: + return AStringPrinterFactory.INSTANCE; + case BINARY: + return ABinaryHexPrinterFactory.INSTANCE; + case RECORD: + return new ARecordPrinterFactory((ARecordType) aqlType); + case ORDEREDLIST: + return new AOrderedlistPrinterFactory((AOrderedListType) aqlType); + case UNORDEREDLIST: + return new AUnorderedlistPrinterFactory((AUnorderedListType) aqlType); + case UNION: + if (((AUnionType) aqlType).isUnknownableType()) { + return new AOptionalFieldPrinterFactory((AUnionType) aqlType); + } else { + return new AUnionPrinterFactory((AUnionType) aqlType); + } + case UUID: + return AUUIDPrinterFactory.INSTANCE; + case SHORTWITHOUTTYPEINFO: + return ShortWithoutTypeInfoPrinterFactory.INSTANCE; + case ANY: + case BITARRAY: + case ENUM: + case SPARSERECORD: + case SYSTEM_NULL: + case TYPE: + case UINT16: + case UINT32: + case UINT64: + case UINT8: + // These types are not intended to be printed to the user. + break; + } + } + return AObjectPrinterFactory.INSTANCE; + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/LinearizeComparatorFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/LinearizeComparatorFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/LinearizeComparatorFactoryProvider.java new file mode 100644 index 0000000..33b32d8 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/LinearizeComparatorFactoryProvider.java @@ -0,0 +1,103 @@ +/* + * 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.formats.nontagged; + +import java.io.Serializable; + +import org.apache.asterix.om.types.ATypeTag; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.data.ILinearizeComparatorFactoryProvider; +import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory; +import org.apache.hyracks.api.dataflow.value.ILinearizeComparator; +import org.apache.hyracks.api.dataflow.value.ILinearizeComparatorFactory; +import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.storage.am.rtree.linearize.HilbertDoubleComparatorFactory; +import org.apache.hyracks.storage.am.rtree.linearize.ZCurveDoubleComparatorFactory; +import org.apache.hyracks.storage.am.rtree.linearize.ZCurveIntComparatorFactory; + +public class LinearizeComparatorFactoryProvider implements ILinearizeComparatorFactoryProvider, Serializable { + + private static final long serialVersionUID = 1L; + public static final LinearizeComparatorFactoryProvider INSTANCE = new LinearizeComparatorFactoryProvider(); + + private LinearizeComparatorFactoryProvider() { + } + + @Override + public ILinearizeComparatorFactory getLinearizeComparatorFactory(Object type, boolean ascending, int dimension) + throws AlgebricksException { + ATypeTag typeTag = (ATypeTag) type; + + if (dimension == 2 && (typeTag == ATypeTag.DOUBLE)) { + return addOffset(new HilbertDoubleComparatorFactory(2), ascending); + } else if (typeTag == ATypeTag.DOUBLE) { + return addOffset(new ZCurveDoubleComparatorFactory(dimension), ascending); + } else if (typeTag == ATypeTag.INT8 || typeTag == ATypeTag.INT16 || typeTag == ATypeTag.INT32 + || typeTag == ATypeTag.INT64) { + return addOffset(new ZCurveIntComparatorFactory(dimension), ascending); + } else { + throw new AlgebricksException("Cannot propose linearizer for key with type " + typeTag + " and dimension " + + dimension + "."); + } + } + + private ILinearizeComparatorFactory addOffset(final IBinaryComparatorFactory inst, final boolean ascending) { + return new ILinearizeComparatorFactory() { + + private static final long serialVersionUID = 1L; + + @Override + public ILinearizeComparator createBinaryComparator() { + final ILinearizeComparator bc = (ILinearizeComparator) inst.createBinaryComparator(); + final int dimension = bc.getDimensions(); + if (ascending) { + return new ILinearizeComparator() { + + @Override + public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) + throws HyracksDataException { + return bc.compare(b1, s1 + 1, l1, b2, s2 + 1, l2); + } + + @Override + public int getDimensions() { + // TODO Auto-generated method stub + return dimension; + } + }; + } else { + return new ILinearizeComparator() { + + @Override + public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) + throws HyracksDataException { + return -bc.compare(b1, s1 + 1, l1, b2, s2 + 1, l2); + } + + @Override + public int getDimensions() { + // TODO Auto-generated method stub + return dimension; + } + }; + } + } + }; + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/LosslessJSONPrinterFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/LosslessJSONPrinterFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/LosslessJSONPrinterFactoryProvider.java new file mode 100644 index 0000000..c508fe6 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/LosslessJSONPrinterFactoryProvider.java @@ -0,0 +1,152 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.dataflow.data.nontagged.printers.adm.AUUIDPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.adm.ShortWithoutTypeInfoPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ABinaryHexPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ABooleanPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ACirclePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADatePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADateTimePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADayTimeDurationPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADoublePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ADurationPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AFloatPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt16PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt32PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt64PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt8PrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AIntervalPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ALinePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ANullPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AOptionalFieldPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AObjectPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AOrderedlistPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.APoint3DPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.APointPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.APolygonPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ARecordPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ARectanglePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AStringPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ATimePrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AUnionPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AUnorderedlistPrinterFactory; +import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AYearMonthDurationPrinterFactory; +import org.apache.asterix.om.types.AOrderedListType; +import org.apache.asterix.om.types.ARecordType; +import org.apache.asterix.om.types.AUnionType; +import org.apache.asterix.om.types.AUnorderedListType; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.data.IPrinterFactory; +import org.apache.hyracks.algebricks.data.IPrinterFactoryProvider; + +public class LosslessJSONPrinterFactoryProvider implements IPrinterFactoryProvider { + + public static final LosslessJSONPrinterFactoryProvider INSTANCE = new LosslessJSONPrinterFactoryProvider(); + + private LosslessJSONPrinterFactoryProvider() { + } + + @Override + public IPrinterFactory getPrinterFactory(Object type) { + IAType aqlType = (IAType) type; + + if (aqlType != null) { + switch (aqlType.getTypeTag()) { + case INT8: + return AInt8PrinterFactory.INSTANCE; + case INT16: + return AInt16PrinterFactory.INSTANCE; + case INT32: + return AInt32PrinterFactory.INSTANCE; + case INT64: + return AInt64PrinterFactory.INSTANCE; + case MISSING: + case NULL: + return ANullPrinterFactory.INSTANCE; + case BOOLEAN: + return ABooleanPrinterFactory.INSTANCE; + case FLOAT: + return AFloatPrinterFactory.INSTANCE; + case DOUBLE: + return ADoublePrinterFactory.INSTANCE; + case TIME: + return ATimePrinterFactory.INSTANCE; + case DATE: + return ADatePrinterFactory.INSTANCE; + case DATETIME: + return ADateTimePrinterFactory.INSTANCE; + case DURATION: + return ADurationPrinterFactory.INSTANCE; + case YEARMONTHDURATION: + return AYearMonthDurationPrinterFactory.INSTANCE; + case DAYTIMEDURATION: + return ADayTimeDurationPrinterFactory.INSTANCE; + case INTERVAL: + return AIntervalPrinterFactory.INSTANCE; + case POINT: + return APointPrinterFactory.INSTANCE; + case POINT3D: + return APoint3DPrinterFactory.INSTANCE; + case LINE: + return ALinePrinterFactory.INSTANCE; + case POLYGON: + return APolygonPrinterFactory.INSTANCE; + case CIRCLE: + return ACirclePrinterFactory.INSTANCE; + case RECTANGLE: + return ARectanglePrinterFactory.INSTANCE; + case STRING: + return AStringPrinterFactory.INSTANCE; + case BINARY: + return ABinaryHexPrinterFactory.INSTANCE; + case RECORD: + return new ARecordPrinterFactory((ARecordType) aqlType); + case ORDEREDLIST: + return new AOrderedlistPrinterFactory((AOrderedListType) aqlType); + case UNORDEREDLIST: + return new AUnorderedlistPrinterFactory((AUnorderedListType) aqlType); + case UNION: + if (((AUnionType) aqlType).isUnknownableType()) { + return new AOptionalFieldPrinterFactory((AUnionType) aqlType); + } else { + return new AUnionPrinterFactory((AUnionType) aqlType); + } + case UUID: + return AUUIDPrinterFactory.INSTANCE; + case SHORTWITHOUTTYPEINFO: + return ShortWithoutTypeInfoPrinterFactory.INSTANCE; + case ANY: + case BITARRAY: + case ENUM: + case SPARSERECORD: + case SYSTEM_NULL: + case TYPE: + case UINT16: + case UINT32: + case UINT64: + case UINT8: + // These types are not intended to be printed to the user. + break; + } + } + return AObjectPrinterFactory.INSTANCE; + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/NormalizedKeyComputerFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/NormalizedKeyComputerFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/NormalizedKeyComputerFactoryProvider.java new file mode 100644 index 0000000..3d04265 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/NormalizedKeyComputerFactoryProvider.java @@ -0,0 +1,89 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.dataflow.data.nontagged.keynormalizers.AWrappedAscNormalizedKeyComputerFactory; +import org.apache.asterix.dataflow.data.nontagged.keynormalizers.AWrappedDescNormalizedKeyComputerFactory; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.data.INormalizedKeyComputerFactoryProvider; +import org.apache.hyracks.api.dataflow.value.INormalizedKeyComputerFactory; +import org.apache.hyracks.dataflow.common.data.normalizers.ByteArrayNormalizedKeyComputerFactory; +import org.apache.hyracks.dataflow.common.data.normalizers.DoubleNormalizedKeyComputerFactory; +import org.apache.hyracks.dataflow.common.data.normalizers.FloatNormalizedKeyComputerFactory; +import org.apache.hyracks.dataflow.common.data.normalizers.Integer64NormalizedKeyComputerFactory; +import org.apache.hyracks.dataflow.common.data.normalizers.IntegerNormalizedKeyComputerFactory; +import org.apache.hyracks.dataflow.common.data.normalizers.UTF8StringNormalizedKeyComputerFactory; + +public class NormalizedKeyComputerFactoryProvider implements INormalizedKeyComputerFactoryProvider { + + public static final NormalizedKeyComputerFactoryProvider INSTANCE = new NormalizedKeyComputerFactoryProvider(); + + private NormalizedKeyComputerFactoryProvider() { + } + + @Override + public INormalizedKeyComputerFactory getNormalizedKeyComputerFactory(Object type, boolean ascending) { + IAType aqlType = (IAType) type; + if (ascending) { + switch (aqlType.getTypeTag()) { + case DATE: + case TIME: + case YEARMONTHDURATION: + case INT32: + return new AWrappedAscNormalizedKeyComputerFactory(new IntegerNormalizedKeyComputerFactory()); + case DATETIME: + case DAYTIMEDURATION: + case INT64: + return new AWrappedAscNormalizedKeyComputerFactory(new Integer64NormalizedKeyComputerFactory()); + case FLOAT: + return new AWrappedAscNormalizedKeyComputerFactory(new FloatNormalizedKeyComputerFactory()); + case DOUBLE: + return new AWrappedAscNormalizedKeyComputerFactory(new DoubleNormalizedKeyComputerFactory()); + case STRING: + return new AWrappedAscNormalizedKeyComputerFactory(new UTF8StringNormalizedKeyComputerFactory()); + case BINARY: + return new AWrappedAscNormalizedKeyComputerFactory(new ByteArrayNormalizedKeyComputerFactory()); + default: + return null; + } + } else { + switch (aqlType.getTypeTag()) { + case DATE: + case TIME: + case YEARMONTHDURATION: + case INT32: + return new AWrappedDescNormalizedKeyComputerFactory(new IntegerNormalizedKeyComputerFactory()); + case DATETIME: + case DAYTIMEDURATION: + case INT64: + return new AWrappedDescNormalizedKeyComputerFactory(new Integer64NormalizedKeyComputerFactory()); + case FLOAT: + return new AWrappedDescNormalizedKeyComputerFactory(new FloatNormalizedKeyComputerFactory()); + case DOUBLE: + return new AWrappedDescNormalizedKeyComputerFactory(new DoubleNormalizedKeyComputerFactory()); + case STRING: + return new AWrappedDescNormalizedKeyComputerFactory(new UTF8StringNormalizedKeyComputerFactory()); + case BINARY: + return new AWrappedDescNormalizedKeyComputerFactory(new ByteArrayNormalizedKeyComputerFactory()); + default: + return null; + } + } + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/8a742fd1/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/PredicateEvaluatorFactoryProvider.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/PredicateEvaluatorFactoryProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/PredicateEvaluatorFactoryProvider.java new file mode 100644 index 0000000..0bc1d2f --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/PredicateEvaluatorFactoryProvider.java @@ -0,0 +1,83 @@ +/* + * 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.formats.nontagged; + +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.EnumDeserializer; +import org.apache.hyracks.api.comm.IFrameTupleAccessor; +import org.apache.hyracks.api.dataflow.value.IPredicateEvaluator; +import org.apache.hyracks.api.dataflow.value.IPredicateEvaluatorFactory; +import org.apache.hyracks.api.dataflow.value.IPredicateEvaluatorFactoryProvider; + +/* +Provides PredicateEvaluator for equi-join cases to properly take care of NULL fields, being compared with each other. +If any of the join keys, from either side, is NULL, record should not pass equi-join condition. +*/ +public class PredicateEvaluatorFactoryProvider implements IPredicateEvaluatorFactoryProvider { + + private static final long serialVersionUID = 1L; + public static final PredicateEvaluatorFactoryProvider INSTANCE = new PredicateEvaluatorFactoryProvider(); + + @Override + public IPredicateEvaluatorFactory getPredicateEvaluatorFactory(final int[] keys0, final int[] keys1) { + + return new IPredicateEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IPredicateEvaluator createPredicateEvaluator() { + return new IPredicateEvaluator() { + + @Override + public boolean evaluate(IFrameTupleAccessor fta0, int tupId0, IFrameTupleAccessor fta1, + int tupId1) { + + int tStart0 = fta0.getTupleStartOffset(tupId0); + int fStartOffset0 = fta0.getFieldSlotsLength() + tStart0; + + for (int k0 : keys0) { + int fieldStartIx = fta0.getFieldStartOffset(tupId0, k0); + ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER + .deserialize(fta0.getBuffer().array()[fieldStartIx + fStartOffset0]); + if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) { + return false; + } + } + + int tStart1 = fta1.getTupleStartOffset(tupId1); + int fStartOffset1 = fta1.getFieldSlotsLength() + tStart1; + + for (int k1 : keys1) { + int fieldStartIx = fta1.getFieldStartOffset(tupId1, k1); + ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER + .deserialize(fta1.getBuffer().array()[fieldStartIx + fStartOffset1]); + if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) { + return false; + } + } + + return true; //none of the fields (from both sides) is NULL + } + }; + } + }; + } + +}
