asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject [1/4] incubator-asterixdb git commit: ASTERIXDB-1281 - Interval format update to AQL and ADM
Date Wed, 03 Feb 2016 16:34:10 GMT
Repository: incubator-asterixdb
Updated Branches:
  refs/heads/master 9dcba3c9f -> d434b50f8


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
deleted file mode 100644
index 25bc7df..0000000
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
+++ /dev/null
@@ -1,165 +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.runtime.evaluators.constructors;
-
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer;
-import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import org.apache.asterix.om.base.AInterval;
-import org.apache.asterix.om.base.AMutableInterval;
-import org.apache.asterix.om.base.ANull;
-import org.apache.asterix.om.base.temporal.ATimeParserFactory;
-import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
-import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
-import org.apache.asterix.om.functions.IFunctionDescriptor;
-import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
-import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.EnumDeserializer;
-import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
-import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
-import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
-import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-public class AIntervalFromTimeConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor
{
-    private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = AsterixBuiltinFunctions.INTERVAL_CONSTRUCTOR_TIME;
-    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory()
{
-        @Override
-        public IFunctionDescriptor createFunctionDescriptor() {
-            return new AIntervalFromTimeConstructorDescriptor();
-        }
-    };
-
-    @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
{
-        return new ICopyEvaluatorFactory() {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws
AlgebricksException {
-                return new ICopyEvaluator() {
-
-                    private DataOutput out = output.getDataOutput();
-
-                    private ArrayBackedValueStorage argOut0 = new ArrayBackedValueStorage();
-                    private ArrayBackedValueStorage argOut1 = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval0 = args[0].createEvaluator(argOut0);
-                    private ICopyEvaluator eval1 = args[1].createEvaluator(argOut1);
-                    private String errorMessage = "This can not be an instance of interval
(from Date)";
-                    //TODO: Where to move and fix these?
-                    private AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte)
0);
-                    @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINTERVAL);
-                    @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ANULL);
-                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
-
-                    @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException
{
-
-                        argOut0.reset();
-                        argOut1.reset();
-                        eval0.evaluate(tuple);
-                        eval1.evaluate(tuple);
-
-                        try {
-
-                            if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                                    || argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG)
{
-                                nullSerde.serialize(ANull.NULL, out);
-                                return;
-                            }
-
-                            long intervalStart = 0, intervalEnd = 0;
-
-                            if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_TIME_TYPE_TAG)
{
-                                intervalStart = ATimeSerializerDeserializer.getChronon(argOut0.getByteArray(),
1);
-                            } else if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG)
{
-                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength()
- 1);
-                                // start date
-                                int stringLength = utf8Ptr.getUTF8Length();
-
-                                intervalStart = ATimeParserFactory.parseTimePart(utf8Ptr.getByteArray(),
-                                        utf8Ptr.getCharStartOffset(), stringLength);
-                            } else {
-                                throw new AlgebricksException(FID.getName()
-                                        + ": expects NULL/STRING/TIME for the first argument,
but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0]));
-                            }
-
-                            if (intervalStart < 0) {
-                                intervalStart += GregorianCalendarSystem.CHRONON_OF_DAY;
-                            }
-
-                            if (argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_TIME_TYPE_TAG)
{
-                                intervalEnd = ATimeSerializerDeserializer.getChronon(argOut1.getByteArray(),
1);
-                            } else if (argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG)
{
-                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength()
- 1);
-                                // start date
-                                int stringLength = utf8Ptr.getUTF8Length();
-
-                                intervalEnd = ATimeParserFactory.parseTimePart(argOut1.getByteArray(),
-                                        utf8Ptr.getCharStartOffset(), stringLength);
-
-                            } else {
-                                throw new AlgebricksException(FID.getName()
-                                        + ": expects NULL/STRING/TIME for the second argument,
but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut1.getByteArray()[0]));
-                            }
-
-                            if (intervalEnd < 0) {
-                                intervalEnd += GregorianCalendarSystem.CHRONON_OF_DAY;
-                            }
-
-                            if (intervalEnd < intervalStart) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": interval end must not be less
than the interval start.");
-                            }
-
-                            aInterval.setValue(intervalStart, intervalEnd, ATypeTag.SERIALIZED_TIME_TYPE_TAG);
-                            intervalSerde.serialize(aInterval, out);
-
-                        } catch (IOException e1) {
-                            throw new AlgebricksException(errorMessage);
-                        } catch (Exception e2) {
-                            throw new AlgebricksException(e2);
-                        }
-                    }
-                };
-            }
-        };
-    }
-
-    @Override
-    public FunctionIdentifier getIdentifier() {
-        return FID;
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
b/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
index 715bba7..27dadfc 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
@@ -150,9 +150,7 @@ import org.apache.asterix.runtime.evaluators.constructors.AInt16ConstructorDescr
 import org.apache.asterix.runtime.evaluators.constructors.AInt32ConstructorDescriptor;
 import org.apache.asterix.runtime.evaluators.constructors.AInt64ConstructorDescriptor;
 import org.apache.asterix.runtime.evaluators.constructors.AInt8ConstructorDescriptor;
-import org.apache.asterix.runtime.evaluators.constructors.AIntervalFromDateConstructorDescriptor;
-import org.apache.asterix.runtime.evaluators.constructors.AIntervalFromDateTimeConstructorDescriptor;
-import org.apache.asterix.runtime.evaluators.constructors.AIntervalFromTimeConstructorDescriptor;
+import org.apache.asterix.runtime.evaluators.constructors.AIntervalConstructorDescriptor;
 import org.apache.asterix.runtime.evaluators.constructors.AIntervalStartFromDateConstructorDescriptor;
 import org.apache.asterix.runtime.evaluators.constructors.AIntervalStartFromDateTimeConstructorDescriptor;
 import org.apache.asterix.runtime.evaluators.constructors.AIntervalStartFromTimeConstructorDescriptor;
@@ -605,9 +603,7 @@ public class NonTaggedDataFormat implements IDataFormat {
         temp.add(DurationFromIntervalDescriptor.FACTORY);
 
         // Interval constructor
-        temp.add(AIntervalFromDateConstructorDescriptor.FACTORY);
-        temp.add(AIntervalFromTimeConstructorDescriptor.FACTORY);
-        temp.add(AIntervalFromDateTimeConstructorDescriptor.FACTORY);
+        temp.add(AIntervalConstructorDescriptor.FACTORY);
         temp.add(AIntervalStartFromDateConstructorDescriptor.FACTORY);
         temp.add(AIntervalStartFromDateTimeConstructorDescriptor.FACTORY);
         temp.add(AIntervalStartFromTimeConstructorDescriptor.FACTORY);
@@ -866,8 +862,9 @@ public class NonTaggedDataFormat implements IDataFormat {
 
         functionTypeInferers.put(AsterixBuiltinFunctions.DEEP_EQUAL, new FunctionTypeInferer()
{
 
-            @Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd,
-                    IVariableTypeEnvironment context) throws AlgebricksException {
+            @Override
+            public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment
context)
+                    throws AlgebricksException {
                 AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
                 IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue());
                 IAType type1 = (IAType) context.getType(f.getArguments().get(1).getValue());
@@ -877,8 +874,9 @@ public class NonTaggedDataFormat implements IDataFormat {
 
         functionTypeInferers.put(AsterixBuiltinFunctions.ADD_FIELDS, new FunctionTypeInferer()
{
 
-            @Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd,
-                    IVariableTypeEnvironment context) throws AlgebricksException {
+            @Override
+            public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment
context)
+                    throws AlgebricksException {
                 AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
                 IAType outType = (IAType) context.getType(expr);
                 IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue());
@@ -896,8 +894,9 @@ public class NonTaggedDataFormat implements IDataFormat {
 
         functionTypeInferers.put(AsterixBuiltinFunctions.REMOVE_FIELDS, new FunctionTypeInferer()
{
 
-            @Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd,
-                    IVariableTypeEnvironment context) throws AlgebricksException {
+            @Override
+            public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment
context)
+                    throws AlgebricksException {
                 AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
                 IAType outType = (IAType) context.getType(expr);
                 IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue());


Mime
View raw message