コード例 #1
0
    @Override
    public IJObject access(
        AListVisitablePointable pointable,
        IObjectPool<IJObject, IAType> objectPool,
        IAType listType,
        JObjectPointableVisitor pointableVisitor)
        throws HyracksDataException {
      List<IVisitablePointable> items = pointable.getItems();
      List<IVisitablePointable> itemTags = pointable.getItemTags();
      JList list = pointable.ordered() ? new JOrderedList(listType) : new JUnorderedList(listType);
      IJObject listItem = null;
      int index = 0;
      try {

        for (IVisitablePointable itemPointable : items) {
          IVisitablePointable itemTagPointable = itemTags.get(index);
          ATypeTag itemTypeTag =
              EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(
                  itemTagPointable.getByteArray()[itemTagPointable.getStartOffset()]);
          typeInfo.reset(listType.getType(), listType.getTypeTag());
          switch (itemTypeTag) {
            case RECORD:
              listItem =
                  pointableVisitor.visit((ARecordVisitablePointable) itemPointable, typeInfo);
              break;
            case UNORDEREDLIST:
            case ORDEREDLIST:
              listItem = pointableVisitor.visit((AListVisitablePointable) itemPointable, typeInfo);
              break;
            case ANY:
              throw new IllegalArgumentException(
                  "Cannot parse list item of type " + listType.getTypeTag());
            default:
              IAType itemType = ((AbstractCollectionType) listType).getItemType();
              typeInfo.reset(itemType, itemType.getTypeTag());
              listItem = pointableVisitor.visit((AFlatValuePointable) itemPointable, typeInfo);
          }
          ATypeTag typeTag =
              EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(
                  itemPointable.getByteArray()[itemPointable.getStartOffset()]);

          list.add(listItem);
        }
      } catch (AsterixException exception) {
        throw new HyracksDataException(exception);
      }
      return list;
    }
コード例 #2
0
    @Override
    public JRecord access(
        ARecordVisitablePointable pointable,
        IObjectPool<IJObject, IAType> objectPool,
        ARecordType recordType,
        JObjectPointableVisitor pointableVisitor)
        throws HyracksDataException {
      try {
        jRecord.reset();
      } catch (AlgebricksException e) {
        throw new HyracksDataException(e);
      }
      ARecordVisitablePointable recordPointable = (ARecordVisitablePointable) pointable;
      List<IVisitablePointable> fieldPointables = recordPointable.getFieldValues();
      List<IVisitablePointable> fieldTypeTags = recordPointable.getFieldTypeTags();
      List<IVisitablePointable> fieldNames = recordPointable.getFieldNames();
      int index = 0;
      boolean closedPart = true;
      try {
        IJObject fieldObject = null;
        for (IVisitablePointable fieldPointable : fieldPointables) {
          closedPart = index < recordType.getFieldTypes().length;
          IVisitablePointable tt = fieldTypeTags.get(index);
          IAType fieldType = closedPart ? recordType.getFieldTypes()[index] : null;
          ATypeTag typeTag =
              EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(
                  tt.getByteArray()[tt.getStartOffset()]);
          IVisitablePointable fieldName = fieldNames.get(index);
          typeInfo.reset(fieldType, typeTag);
          switch (typeTag) {
            case RECORD:
              fieldObject =
                  pointableVisitor.visit((ARecordVisitablePointable) fieldPointable, typeInfo);
              break;
            case ORDEREDLIST:
            case UNORDEREDLIST:
              if (fieldPointable instanceof AFlatValuePointable) {
                // value is null
                fieldObject = null;
              } else {
                fieldObject =
                    pointableVisitor.visit((AListVisitablePointable) fieldPointable, typeInfo);
              }
              break;
            case ANY:
              break;
            default:
              fieldObject = pointableVisitor.visit((AFlatValuePointable) fieldPointable, typeInfo);
          }
          if (closedPart) {
            jObjects[index] = fieldObject;
          } else {
            byte[] b = fieldName.getByteArray();
            int s = fieldName.getStartOffset();
            int l = fieldName.getLength();
            String v =
                AStringSerializerDeserializer.INSTANCE
                    .deserialize(new DataInputStream(new ByteArrayInputStream(b, s + 1, l - 1)))
                    .getStringValue();
            openFields.put(v, fieldObject);
          }
          index++;
          fieldObject = null;
        }

      } catch (Exception e) {
        e.printStackTrace();
        throw new HyracksDataException(e);
      }
      return jRecord;
    }