Ejemplo n.º 1
0
  private void decodeArrayString(
      int index, Type field, Group pqGroup, String arrayString, char delim) throws IOException {
    //		for parquet, we only have one-dimention array
    //		anotation support: decimal, time, timestamp
    String[] splits = FormatHandlerUtil.getArraySplits(arrayString.toCharArray(), delim);

    for (String elementString : splits) {
      switch (field.asPrimitiveType().getPrimitiveTypeName()) {
        case BOOLEAN:
          pqGroup.add(index, Boolean.parseBoolean(elementString));
          break;

        case INT32:
          if (columnSchemas.get(index).getType() == GPDBWritable.DATE) {
            pqGroup.add(
                index,
                (int)
                    FormatHandlerUtil.getTimeDiff(
                        elementString, "1970-01-01", "yyyy-mm-dd", 24 * 60 * 60 * 1000));
          } else if (columnSchemas.get(index).getType() == GPDBWritable.TIME) {
            pqGroup.add(
                index,
                (int) FormatHandlerUtil.getTimeDiff(elementString, "00:00:00", "mm:hh:ss", 1));
          } else {
            pqGroup.add(index, Integer.parseInt(elementString));
          }
          break;

        case INT64:
          if (columnSchemas.get(index).getType() == GPDBWritable.TIMESTAMP) {
            pqGroup.add(
                index,
                FormatHandlerUtil.getTimeDiff(
                    elementString, "1970-01-01 00:00:00", "yyyy-mm-dd mm:hh:ss", 1));
          } else {
            pqGroup.add(index, Long.parseLong(elementString));
          }
          break;

        case FLOAT:
          pqGroup.add(index, Float.parseFloat(elementString));
          break;

        case DOUBLE:
          pqGroup.add(index, Double.parseDouble(elementString));
          break;

        case INT96:
        case BINARY:
        case FIXED_LEN_BYTE_ARRAY:
          OriginalType type = field.getOriginalType();
          if (type == OriginalType.UTF8 || type == OriginalType.JSON) {
            pqGroup.add(index, elementString);
          } else if (type == OriginalType.DECIMAL) {
            pqGroup.add(index, Binary.fromByteArray(elementString.getBytes()));
          } else if (type == OriginalType.INTERVAL) {
            pqGroup.add(
                index, Binary.fromByteArray(FormatHandlerUtil.getParquetInterval(elementString)));
          } else {
            pqGroup.add(
                index,
                Binary.fromByteArray(FormatHandlerUtil.octString2byteArray(elementString).array()));
          }
          break;

        default:
          throw new IOException(
              "internal error, you should not be here, pqtype:"
                  + field.asPrimitiveType().getPrimitiveTypeName());
      }
    }
  }
Ejemplo n.º 2
0
  private void fillElement(int index, int colType, Group pqGroup, GPDBWritable gw, Type field)
      throws IOException {
    switch (colType) {
      case GPDBWritable.BPCHAR:
      case GPDBWritable.CHAR:
      case GPDBWritable.DATE:
      case GPDBWritable.NUMERIC:
      case GPDBWritable.TIME:
      case GPDBWritable.TIMESTAMP:
      case GPDBWritable.VARCHAR:
      case GPDBWritable.TEXT:
        //				utf8 or array
        if (field.getRepetition() == Repetition.REPEATED) {
          decodeArrayString(
              index, field, pqGroup, gw.getString(index), columnSchemas.get(index).getDelim());
        } else {
          int gpdbType = columnSchemas.get(index).getType();
          PrimitiveTypeName priType = field.asPrimitiveType().getPrimitiveTypeName();
          OriginalType originalType = field.getOriginalType();

          if (gpdbType == GPDBWritable.NUMERIC && priType == PrimitiveTypeName.INT32) {
            pqGroup.add(index, Integer.parseInt(gw.getString(index)));
          } else if (gpdbType == GPDBWritable.NUMERIC && priType == PrimitiveTypeName.INT64) {
            pqGroup.add(index, Long.parseLong(gw.getString(index)));
          } else if (gpdbType == GPDBWritable.DATE && priType == PrimitiveTypeName.INT32) {
            pqGroup.add(
                index,
                (int)
                    FormatHandlerUtil.getTimeDiff(
                        gw.getString(index), "1970-01-01", "yyyy-mm-dd", 24 * 60 * 60 * 1000));
          } else if (gpdbType == GPDBWritable.TIME && priType == PrimitiveTypeName.INT32) {
            pqGroup.add(
                index,
                (int)
                    FormatHandlerUtil.getTimeDiff(gw.getString(index), "00:00:00", "mm:hh:ss", 1));
          } else if (gpdbType == GPDBWritable.TIMESTAMP && priType == PrimitiveTypeName.INT64) {
            pqGroup.add(
                index,
                FormatHandlerUtil.getTimeDiff(
                    gw.getString(index), "1970-01-01 00:00:00", "yyyy-mm-dd mm:hh:ss", 1));
          } else if (gpdbType == GPDBWritable.INTERVAL && originalType == OriginalType.INTERVAL) {
            //						interval is complex, we just use string, for now, we just support 'postgres'
            // style interval
            //						1 year 2 mons -3 days +04:05:06.00901
            byte[] interval = FormatHandlerUtil.getParquetInterval(gw.getString(index));
            pqGroup.add(index, Binary.fromByteArray(interval));
          } else {
            pqGroup.add(index, gw.getString(index));
          }
        }
        break;

      case GPDBWritable.BYTEA:
        pqGroup.add(index, Binary.fromByteArray(gw.getBytes(index)));
        break;

      case GPDBWritable.REAL:
        pqGroup.add(index, gw.getFloat(index));
        break;

      case GPDBWritable.BIGINT:
        pqGroup.add(index, gw.getLong(index));
        break;

      case GPDBWritable.BOOLEAN:
        pqGroup.add(index, gw.getBoolean(index));
        break;

      case GPDBWritable.FLOAT8:
        pqGroup.add(index, gw.getDouble(index));
        break;

      case GPDBWritable.INTEGER:
        pqGroup.add(index, gw.getInt(index));
        break;

      case GPDBWritable.SMALLINT:
        pqGroup.add(index, gw.getShort(index));
        break;

      default:
        throw new IOException("internal error, not support type, typeId:" + colType);
    }
  }