asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [1/2] incubator-asterixdb git commit: ASTERIXDB-1159: make ARecordType read-only and separate its mutable state to RuntimeRecordTypeInfo.
Date Thu, 19 Nov 2015 01:06:49 GMT
Repository: incubator-asterixdb
Updated Branches:
  refs/heads/master d1b19bbf9 -> 754539621


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/75453962/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedEvalFactory.java
b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedEvalFactory.java
index 883be0a..2f41816 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedEvalFactory.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedEvalFactory.java
@@ -22,6 +22,7 @@ import java.io.DataOutput;
 import java.util.List;
 
 import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
@@ -50,22 +51,27 @@ public class FieldAccessNestedEvalFactory implements ICopyEvaluatorFactory
{
     public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException
{
         return new ICopyEvaluator() {
 
-            private DataOutput out = output.getDataOutput();
-            private ByteArrayAccessibleOutputStream subRecordTmpStream = new ByteArrayAccessibleOutputStream();
+            private final DataOutput out = output.getDataOutput();
+            private final ByteArrayAccessibleOutputStream subRecordTmpStream = new ByteArrayAccessibleOutputStream();
 
-            private ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
-            private ICopyEvaluator eval0 = recordEvalFactory.createEvaluator(outInput0);
-            private ArrayBackedValueStorage[] abvsFields = new ArrayBackedValueStorage[fieldPath.size()];
-            private DataOutput[] doFields = new DataOutput[fieldPath.size()];
+            private final ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
+            private final ICopyEvaluator eval0 = recordEvalFactory.createEvaluator(outInput0);
+            private final ArrayBackedValueStorage[] abvsFields = new ArrayBackedValueStorage[fieldPath.size()];
+            private final DataOutput[] doFields = new DataOutput[fieldPath.size()];
+            private final RuntimeRecordTypeInfo[] recTypeInfos = new RuntimeRecordTypeInfo[fieldPath.size()];
 
             {
                 FieldAccessUtil.getFieldsAbvs(abvsFields, doFields, fieldPath);
-                recordType = recordType.deepCopy(recordType);
+                for (int index = 0; index < fieldPath.size(); ++index) {
+                    recTypeInfos[index] = new RuntimeRecordTypeInfo();
+                }
+
             }
 
             @Override
             public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                FieldAccessUtil.evaluate(tuple, out, eval0, abvsFields, outInput0, subRecordTmpStream,
recordType);
+                FieldAccessUtil.evaluate(tuple, out, eval0, abvsFields, outInput0, subRecordTmpStream,
recordType,
+                        recTypeInfos);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/75453962/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessUtil.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessUtil.java
b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessUtil.java
index db8a6b4..a442ef4 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessUtil.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessUtil.java
@@ -34,9 +34,10 @@ import org.apache.asterix.om.types.AUnionType;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.om.types.IAType;
+import org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo;
 import org.apache.asterix.om.util.NonTaggedFormatUtil;
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -89,8 +90,8 @@ public class FieldAccessUtil {
 
     public static void evaluate(IFrameTupleReference tuple, DataOutput out, ICopyEvaluator
eval0,
             ArrayBackedValueStorage[] abvsFields, ArrayBackedValueStorage abvsRecord,
-            ByteArrayAccessibleOutputStream subRecordTmpStream, ARecordType recordType) throws
AlgebricksException {
-
+            ByteArrayAccessibleOutputStream subRecordTmpStream, ARecordType recordType,
+            RuntimeRecordTypeInfo[] recTypeInfos) throws AlgebricksException {
         try {
             abvsRecord.reset();
             eval0.evaluate(tuple);
@@ -99,7 +100,10 @@ public class FieldAccessUtil {
             int subFieldOffset = -1;
             int subFieldLength = -1;
             int nullBitmapSize = -1;
+
             IAType subType = recordType;
+            recTypeInfos[0].reset(recordType);
+
             ATypeTag subTypeTag = ATypeTag.NULL;
             byte[] subRecord = abvsRecord.getByteArray();
             boolean openField = false;
@@ -117,9 +121,11 @@ public class FieldAccessUtil {
                     if (subType.getTypeTag().serialize() != SER_RECORD_TYPE_TAG) {
                         throw new AlgebricksException("Field accessor is not defined for
values of type " + subTypeTag);
                     }
-
+                    if (subType.getTypeTag() == ATypeTag.RECORD) {
+                        recTypeInfos[i].reset((ARecordType) subType);
+                    }
                 }
-                subFieldIndex = ((ARecordType) subType).findFieldPosition(abvsFields[i].getByteArray(),
+                subFieldIndex = recTypeInfos[i].getFieldIndex(abvsFields[i].getByteArray(),
                         abvsFields[i].getStartOffset() + 1, abvsFields[i].getLength());
                 if (subFieldIndex == -1) {
                     break;
@@ -133,6 +139,10 @@ public class FieldAccessUtil {
                     return;
                 }
                 subType = ((ARecordType) subType).getFieldTypes()[subFieldIndex];
+                if (subType.getTypeTag() == ATypeTag.RECORD && i + 1 < abvsFields.length)
{
+                    // Move to the next Depth
+                    recTypeInfos[i + 1].reset((ARecordType) subType);
+                }
                 if (subType.getTypeTag().equals(ATypeTag.UNION)) {
                     if (((AUnionType) subType).isNullableType()) {
                         subTypeTag = ((AUnionType) subType).getNullableType().getTypeTag();
@@ -172,7 +182,8 @@ public class FieldAccessUtil {
                 }
 
                 subTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(subRecord[subFieldOffset]);
-                subFieldLength = NonTaggedFormatUtil.getFieldValueLength(subRecord, subFieldOffset,
subTypeTag, true) + 1;
+                subFieldLength = NonTaggedFormatUtil.getFieldValueLength(subRecord, subFieldOffset,
subTypeTag, true)
+                        + 1;
 
                 if (i < abvsFields.length - 1) {
                     //setup next iteration
@@ -187,7 +198,6 @@ public class FieldAccessUtil {
                 out.writeByte(subTypeTag.serialize());
             }
             out.write(subRecord, subFieldOffset, subFieldLength);
-
         } catch (IOException e) {
             throw new AlgebricksException(e);
         } catch (AsterixException e) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/75453962/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
index 05e7292..8cabee1 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
@@ -26,6 +26,7 @@ import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
@@ -56,26 +57,29 @@ public class GetRecordFieldValueEvalFactory implements ICopyEvaluatorFactory
{
     public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException
{
         return new ICopyEvaluator() {
 
-            private DataOutput out = output.getDataOutput();
-            private ByteArrayAccessibleOutputStream subRecordTmpStream = new ByteArrayAccessibleOutputStream();
+            private final DataOutput out = output.getDataOutput();
+            private final ByteArrayAccessibleOutputStream subRecordTmpStream = new ByteArrayAccessibleOutputStream();
 
-            private ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
-            private ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
-            private ICopyEvaluator eval0 = recordEvalFactory.createEvaluator(outInput0);
-            private ICopyEvaluator eval1 = fldNameEvalFactory.createEvaluator(outInput1);
+            private final ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
+            private final ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
+            private final ICopyEvaluator eval0 = recordEvalFactory.createEvaluator(outInput0);
+            private final ICopyEvaluator eval1 = fldNameEvalFactory.createEvaluator(outInput1);
 
-            int size = 1;
-            private ArrayBackedValueStorage abvsFields[] = new ArrayBackedValueStorage[size];
-            private DataOutput[] doFields = new DataOutput[size];
+            private final int size = 1;
+            private final ArrayBackedValueStorage abvsFields[] = new ArrayBackedValueStorage[size];
+            private final DataOutput[] doFields = new DataOutput[size];
 
             @SuppressWarnings("unchecked")
-            private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+            private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                     .getSerializerDeserializer(BuiltinType.ANULL);
+            private final RuntimeRecordTypeInfo[] recTypeInfos = new RuntimeRecordTypeInfo[size];
 
-            private ARecordType mRecordType = recordType.deepCopy(recordType);
             {
                 abvsFields[0] = new ArrayBackedValueStorage();
                 doFields[0] = abvsFields[0].getDataOutput();
+                for (int index = 0; index < size; ++index) {
+                    recTypeInfos[index] = new RuntimeRecordTypeInfo();
+                }
             }
 
             @Override
@@ -92,7 +96,8 @@ public class GetRecordFieldValueEvalFactory implements ICopyEvaluatorFactory
{
                     abvsFields[0].reset();
                     doFields[0].write(serFldName);
 
-                    FieldAccessUtil.evaluate(tuple, out, eval0, abvsFields, outInput0, subRecordTmpStream,
mRecordType);
+                    FieldAccessUtil.evaluate(tuple, out, eval0, abvsFields, outInput0, subRecordTmpStream,
recordType,
+                            recTypeInfos);
                 } catch (IOException e) {
                     throw new AlgebricksException(e);
                 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/75453962/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
index 3fc5db1..d8bafc0 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
@@ -69,8 +69,7 @@ public class GetRecordFieldsEvalFactory implements ICopyEvaluatorFactory
{
             private DataOutput out = output.getDataOutput();
             private RecordFieldsUtil rfu = new RecordFieldsUtil();
 
-            protected ARecordType mRecordType = recordType.deepCopy(recordType);
-
+            @Override
             public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                 outInput0.reset();
                 eval0.evaluate(tuple);
@@ -91,7 +90,7 @@ public class GetRecordFieldsEvalFactory implements ICopyEvaluatorFactory
{
                 recordPointable.set(outInput0.getByteArray(), outInput0.getStartOffset(),
outInput0.getLength());
 
                 try {
-                    rfu.processRecord(recordPointable, mRecordType, out, 0);
+                    rfu.processRecord(recordPointable, recordType, out, 0);
                 } catch (IOException e) {
                     e.printStackTrace();
                 } catch (AsterixException e) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/75453962/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
index 76716b1..bbba625 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
@@ -176,8 +176,8 @@ public class RecordFieldsUtil {
         orderedListBuilder.write(out, true);
     }
 
-    public void addNameField(IValueReference nameArg, IARecordBuilder fieldRecordBuilder)
throws HyracksDataException,
-            AsterixException {
+    public void addNameField(IValueReference nameArg, IARecordBuilder fieldRecordBuilder)
+            throws HyracksDataException, AsterixException {
         ArrayBackedValueStorage fieldAbvs = getTempBuffer();
 
         fieldAbvs.reset();
@@ -185,8 +185,8 @@ public class RecordFieldsUtil {
         fieldRecordBuilder.addField(fieldAbvs, nameArg);
     }
 
-    public void addFieldType(byte tagId, IARecordBuilder fieldRecordBuilder) throws HyracksDataException,
-            AsterixException {
+    public void addFieldType(byte tagId, IARecordBuilder fieldRecordBuilder)
+            throws HyracksDataException, AsterixException {
         ArrayBackedValueStorage fieldAbvs = getTempBuffer();
         ArrayBackedValueStorage valueAbvs = getTempBuffer();
 
@@ -202,8 +202,8 @@ public class RecordFieldsUtil {
         fieldRecordBuilder.addField(fieldAbvs, valueAbvs);
     }
 
-    public void addIsOpenField(boolean isOpen, IARecordBuilder fieldRecordBuilder) throws
HyracksDataException,
-            AsterixException {
+    public void addIsOpenField(boolean isOpen, IARecordBuilder fieldRecordBuilder)
+            throws HyracksDataException, AsterixException {
         ArrayBackedValueStorage fieldAbvs = getTempBuffer();
         ArrayBackedValueStorage valueAbvs = getTempBuffer();
 
@@ -246,9 +246,9 @@ public class RecordFieldsUtil {
         valueAbvs.reset();
         ARecordType newType;
         if (fieldType == null) {
-            newType = openType.deepCopy(openType);
+            newType = openType;
         } else {
-            newType = ((ARecordType) fieldType).deepCopy((ARecordType) fieldType);
+            newType = (ARecordType) fieldType;
         }
         ARecordPointable recordP = getRecordPointable();
         recordP.set(recordArg);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/75453962/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
index df52f90..cdecce5 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
@@ -66,6 +66,7 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
     private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory()
{
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new RecordMergeDescriptor();
         }
@@ -112,15 +113,13 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
                 final ICopyEvaluator eval0 = args[0].createEvaluator(abvs0);
                 final ICopyEvaluator eval1 = args[1].createEvaluator(abvs1);
 
-                final Stack<RecordBuilder> rbStack = new Stack<RecordBuilder>();
-
-                final ArrayBackedValueStorage tabvs = new ArrayBackedValueStorage();
-
-                final ByteArrayAccessibleOutputStream nameOutputStream = new ByteArrayAccessibleOutputStream();
-                final ByteArrayInputStream namebais = new ByteArrayInputStream(nameOutputStream.getByteArray());
-                final DataInputStream namedis = new DataInputStream(namebais);
-
                 return new ICopyEvaluator() {
+                    private final Stack<RecordBuilder> rbStack = new Stack<RecordBuilder>();
+                    private final ArrayBackedValueStorage tabvs = new ArrayBackedValueStorage();
+                    private final ByteArrayAccessibleOutputStream nameOutputStream = new
ByteArrayAccessibleOutputStream();
+                    private final ByteArrayInputStream namebais = new ByteArrayInputStream(
+                            nameOutputStream.getByteArray());
+                    private final DataInputStream namedis = new DataInputStream(namebais);
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException
{
@@ -156,8 +155,8 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
                     }
 
                     private void mergeFields(ARecordType combinedType, ARecordVisitablePointable
leftRecord,
-                            ARecordVisitablePointable rightRecord, boolean openFromParent,
int nestedLevel) throws IOException,
-                            AsterixException, AlgebricksException {
+                            ARecordVisitablePointable rightRecord, boolean openFromParent,
int nestedLevel)
+                                    throws IOException, AsterixException, AlgebricksException
{
                         if (rbStack.size() < (nestedLevel + 1)) {
                             rbStack.push(new RecordBuilder());
                         }
@@ -225,13 +224,13 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
 
                         //Add the merged field
                         if (combinedType.isClosedField(fieldName)) {
-                            int pos = combinedType.findFieldPosition(fieldName);
+                            int pos = combinedType.getFieldIndex(fieldName);
                             if (rightValue == null) {
                                 rbStack.get(nestedLevel).addField(pos, leftValue);
                             } else {
                                 mergeFields((ARecordType) combinedType.getFieldType(fieldName),
-                                        (ARecordVisitablePointable) leftValue, (ARecordVisitablePointable)
rightValue, false,
-                                        nestedLevel + 1);
+                                        (ARecordVisitablePointable) leftValue, (ARecordVisitablePointable)
rightValue,
+                                        false, nestedLevel + 1);
                                 tabvs.reset();
                                 rbStack.get(nestedLevel + 1).write(tabvs.getDataOutput(),
true);
                                 rbStack.get(nestedLevel).addField(pos, tabvs);
@@ -241,8 +240,8 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
                                 rbStack.get(nestedLevel).addField(fieldNamePointable, leftValue);
                             } else {
                                 mergeFields((ARecordType) combinedType.getFieldType(fieldName),
-                                        (ARecordVisitablePointable) leftValue, (ARecordVisitablePointable)
rightValue, false,
-                                        nestedLevel + 1);
+                                        (ARecordVisitablePointable) leftValue, (ARecordVisitablePointable)
rightValue,
+                                        false, nestedLevel + 1);
                                 tabvs.reset();
                                 rbStack.get(nestedLevel + 1).write(tabvs.getDataOutput(),
true);
                                 rbStack.get(nestedLevel).addField(fieldNamePointable, tabvs);


Mime
View raw message