private void assignRowColumn()

in ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorAssignRow.java [354:636]


  private void assignRowColumn(
      ColumnVector columnVector, int batchIndex, TypeInfo targetTypeInfo, Object object) {

    if (object == null) {
      assignNullRowColumn(columnVector, batchIndex, targetTypeInfo);
      return;
    }
    switch (targetTypeInfo.getCategory()) {
    case PRIMITIVE:
      {
        final PrimitiveCategory targetPrimitiveCategory =
            ((PrimitiveTypeInfo) targetTypeInfo).getPrimitiveCategory();
        switch (targetPrimitiveCategory) {
        case VOID:
          VectorizedBatchUtil.setNullColIsNullValue(columnVector, batchIndex);
          return;
        case BOOLEAN:
          if (object instanceof Boolean) {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                (((Boolean) object) ? 1 : 0);
          } else {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                (((BooleanWritable) object).get() ? 1 : 0);
          }
          break;
        case BYTE:
          if (object instanceof Byte) {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((Byte) object);
          } else {
            ((LongColumnVector) columnVector).vector[batchIndex] =
               ((ByteWritable) object).get();
          }
          break;
        case SHORT:
          if (object instanceof Short) {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((Short) object);
          } else {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((ShortWritable) object).get();
          }
          break;
        case INT:
          if (object instanceof Integer) {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((Integer) object);
          } else {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((IntWritable) object).get();
          }
          break;
        case LONG:
          if (object instanceof Long) {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((Long) object);
          } else {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((LongWritable) object).get();
          }
          break;
        case TIMESTAMP:
          if (object instanceof Timestamp) {
            ((TimestampColumnVector) columnVector).set(
                batchIndex, ((Timestamp) object).toSqlTimestamp());
          } else {
            ((TimestampColumnVector) columnVector).set(
                batchIndex, ((TimestampWritableV2) object).getTimestamp().toSqlTimestamp());
          }
          break;
        case DATE:
          if (object instanceof Date) {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                DateWritableV2.dateToDays((Date) object);
          } else {
            ((LongColumnVector) columnVector).vector[batchIndex] =
               ((DateWritableV2) object).getDays();
          }
          break;
        case FLOAT:
          if (object instanceof Float) {
            ((DoubleColumnVector) columnVector).vector[batchIndex] =
                ((Float) object);
          } else {
            ((DoubleColumnVector) columnVector).vector[batchIndex] =
                ((FloatWritable) object).get();
          }
          break;
        case DOUBLE:
          if (object instanceof Double) {
            ((DoubleColumnVector) columnVector).vector[batchIndex] =
                ((Double) object);
          } else {
            ((DoubleColumnVector) columnVector).vector[batchIndex] =
                ((DoubleWritable) object).get();
          }
          break;
        case BINARY:
          {
            if (object instanceof byte[]) {
              byte[] bytes = (byte[]) object;
              ((BytesColumnVector) columnVector).setVal(
                  batchIndex, bytes, 0, bytes.length);
            } else {
              BytesWritable bw = (BytesWritable) object;
              ((BytesColumnVector) columnVector).setVal(
                  batchIndex, bw.getBytes(), 0, bw.getLength());
            }
          }
          break;
        case STRING:
          {
            if (object instanceof String) {
              String string = (String) object;
              byte[] bytes = string.getBytes();
              ((BytesColumnVector) columnVector).setVal(
                  batchIndex, bytes, 0, bytes.length);
            } else {
              Text tw = (Text) object;
              ((BytesColumnVector) columnVector).setVal(
                  batchIndex, tw.getBytes(), 0, tw.getLength());
            }
          }
          break;
        case VARCHAR:
          {
            // UNDONE: Performance problem with conversion to String, then bytes...

            // We store VARCHAR type stripped of pads.
            HiveVarchar hiveVarchar;
            if (object instanceof HiveVarchar) {
              hiveVarchar = (HiveVarchar) object;
            } else {
              hiveVarchar = ((HiveVarcharWritable) object).getHiveVarchar();
            }

            // TODO: HIVE-13624 Do we need maxLength checking?

            byte[] bytes = hiveVarchar.getValue().getBytes();
            ((BytesColumnVector) columnVector).setVal(
                batchIndex, bytes, 0, bytes.length);
          }
          break;
        case CHAR:
          {
            // UNDONE: Performance problem with conversion to String, then bytes...

            // We store CHAR type stripped of pads.
            HiveChar hiveChar;
            if (object instanceof HiveChar) {
              hiveChar = (HiveChar) object;
            } else {
              hiveChar = ((HiveCharWritable) object).getHiveChar();
            }

            // TODO: HIVE-13624 Do we need maxLength checking?

            // We store CHAR in vector row batch with padding stripped.
            byte[] bytes = hiveChar.getStrippedValue().getBytes();
            ((BytesColumnVector) columnVector).setVal(
                batchIndex, bytes, 0, bytes.length);
          }
          break;
        case DECIMAL:
          if (columnVector instanceof DecimalColumnVector) {
            if (object instanceof HiveDecimal) {
              ((DecimalColumnVector) columnVector).set(
                  batchIndex, (HiveDecimal) object);
            } else {
              ((DecimalColumnVector) columnVector).set(
                  batchIndex, (HiveDecimalWritable) object);
            }
          } else {
            if (object instanceof HiveDecimal) {
              ((Decimal64ColumnVector) columnVector).set(
                  batchIndex, (HiveDecimal) object);
            } else {
              ((Decimal64ColumnVector) columnVector).set(
                  batchIndex, (HiveDecimalWritable) object);
            }
          }
          break;
        case INTERVAL_YEAR_MONTH:
          if (object instanceof HiveIntervalYearMonth) {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((HiveIntervalYearMonth) object).getTotalMonths();
          } else {
            ((LongColumnVector) columnVector).vector[batchIndex] =
                ((HiveIntervalYearMonthWritable) object).getHiveIntervalYearMonth().getTotalMonths();
          }
          break;
        case INTERVAL_DAY_TIME:
          if (object instanceof HiveIntervalDayTime) {
            ((IntervalDayTimeColumnVector) columnVector).set(
                batchIndex, (HiveIntervalDayTime) object);
          } else {
            ((IntervalDayTimeColumnVector) columnVector).set(
                batchIndex, ((HiveIntervalDayTimeWritable) object).getHiveIntervalDayTime());
          }
          break;
        default:
          throw new RuntimeException("Primitive category " + targetPrimitiveCategory.name() +
              " not supported");
        }
      }
      break;
    case LIST:
      {
        final ListColumnVector listColumnVector = (ListColumnVector) columnVector;
        final ListTypeInfo listTypeInfo = (ListTypeInfo) targetTypeInfo;
        final TypeInfo elementTypeInfo = listTypeInfo.getListElementTypeInfo();
        final List list = (List) object;
        final int size = list.size();
        final int childCount = listColumnVector.childCount;
        listColumnVector.offsets[batchIndex] = childCount;
        listColumnVector.lengths[batchIndex] = size;
        listColumnVector.childCount = childCount + size;
        listColumnVector.child.ensureSize(childCount + size, true);

        for (int i = 0; i < size; i++) {
          assignRowColumn(listColumnVector.child, childCount + i, elementTypeInfo, list.get(i));
        }
      }
      break;
    case MAP:
      {
        final MapColumnVector mapColumnVector = (MapColumnVector) columnVector;
        final MapTypeInfo mapTypeInfo = (MapTypeInfo) targetTypeInfo;
        final Map<Object, Object> map = (Map<Object, Object>) object;
        final int size = map.size();
        int childCount = mapColumnVector.childCount;
        mapColumnVector.offsets[batchIndex] = childCount;
        mapColumnVector.lengths[batchIndex] = size;
        mapColumnVector.keys.ensureSize(childCount + size, true);
        mapColumnVector.values.ensureSize(childCount + size, true);

        for (Map.Entry<Object, Object> entry : map.entrySet()) {
          assignRowColumn(mapColumnVector.keys, childCount, mapTypeInfo.getMapKeyTypeInfo(), entry.getKey());
          assignRowColumn(mapColumnVector.values, childCount, mapTypeInfo.getMapValueTypeInfo(), entry.getValue());
          childCount++;
        }
        mapColumnVector.childCount = childCount;
      }
      break;
    case STRUCT:
      {
        final StructColumnVector structColumnVector = (StructColumnVector) columnVector;
        final StructTypeInfo targetStructTypeInfo = (StructTypeInfo) targetTypeInfo;
        final List<TypeInfo> targetFieldTypeInfos = targetStructTypeInfo.getAllStructFieldTypeInfos();
        final int size = targetFieldTypeInfos.size();
        if (object instanceof List) {
          final List struct = (List) object;
          for (int i = 0; i < size; i++) {
            assignRowColumn(structColumnVector.fields[i], batchIndex, targetFieldTypeInfos.get(i), struct.get(i));
          }
        } else {
          final Object[] array = (Object[]) object;
          for (int i = 0; i < size; i++) {
            assignRowColumn(structColumnVector.fields[i], batchIndex, targetFieldTypeInfos.get(i), array[i]);
          }
        }
      }
      break;
    case UNION:
      {
        final StandardUnion union = (StandardUnion) object;
        final UnionColumnVector unionColumnVector = (UnionColumnVector) columnVector;
        final UnionTypeInfo unionTypeInfo = (UnionTypeInfo) targetTypeInfo;
        final List<TypeInfo> objectTypeInfos = unionTypeInfo.getAllUnionObjectTypeInfos();
        final byte tag = union.getTag();
        unionColumnVector.tags[batchIndex] = tag;
        assignRowColumn(unionColumnVector.fields[tag], batchIndex, objectTypeInfos.get(tag), union.getObject());
      }
      break;
    default:
      throw new RuntimeException("Category " + targetTypeInfo.getCategory().name() + " not supported");
    }

    /*
     * We always set the null flag to false when there is a value.
     */
    columnVector.isNull[batchIndex] = false;
  }