Esempio n. 1
0
  @Override
  public Datum eval(Tuple params) {

    if (params.isBlankOrNull(0) || params.isBlankOrNull(1)) {
      return NullDatum.get();
    }

    String fillText;
    if (hasFillCharacters) {
      fillText = params.getText(2);
    } else {
      fillText = " ";
    }

    String input = params.getText(0);
    int expected = params.getInt4(1);

    int templen = expected - params.size(0);

    if (templen <= 0) {
      return DatumFactory.createText(input.substring(0, expected));
    } else {
      return DatumFactory.createText(StringUtils.leftPad(input, expected, fillText));
    }
  }
Esempio n. 2
0
  @Override
  public Datum eval(Tuple tuple) {
    Datum resultDatum;

    for (int i = 0; i < tuple.size(); i++) {
      params[i] = WritableTypeConverter.convertDatum2Writable(tuple.asDatum(i));
    }

    try {
      Writable result = (Writable) evalMethod.invoke(instance, params);
      resultDatum = WritableTypeConverter.convertWritable2Datum(result);
    } catch (Exception e) {
      throw new TajoInternalError(e);
    }

    return resultDatum;
  }
Esempio n. 3
0
  private void writeValue(Column column, Tuple tuple, int index) {
    switch (column.getDataType().getType()) {
      case BOOLEAN:
        recordConsumer.addBoolean(tuple.getBool(index));
        break;
      case BIT:
      case INT2:
      case INT4:
        recordConsumer.addInteger(tuple.getInt4(index));
        break;
      case INT8:
        recordConsumer.addLong(tuple.getInt8(index));
        break;
      case FLOAT4:
        recordConsumer.addFloat(tuple.getFloat4(index));
        break;
      case FLOAT8:
        recordConsumer.addDouble(tuple.getFloat8(index));
        break;
      case CHAR:
        if (tuple.size(index) > column.getDataType().getLength()) {
          throw new ValueTooLongForTypeCharactersException(column.getDataType().getLength());
        }

        recordConsumer.addBinary(Binary.fromByteArray(tuple.getTextBytes(index)));
        break;
      case TEXT:
        recordConsumer.addBinary(Binary.fromByteArray(tuple.getTextBytes(index)));
        break;
      case DATE:
        // Parquet DATE type is based on Unix Epoch(Jan 1, 1970).
        recordConsumer.addInteger(tuple.getInt4(index) - DateTimeConstants.UNIX_EPOCH_JDATE);
        break;
      case PROTOBUF:
      case BLOB:
        recordConsumer.addBinary(Binary.fromByteArray(tuple.getBytes(index)));
        break;
      default:
        break;
    }
  }