org.apache.orc.storage.ql.exec.vector.DecimalColumnVector Java Examples

The following examples show how to use org.apache.orc.storage.ql.exec.vector.DecimalColumnVector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SparkOrcReader.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public void convert(UnsafeRowWriter writer, int column, ColumnVector vector,
                    int row) {
  if (vector.isRepeating) {
    row = 0;
  }
  if (!vector.noNulls && vector.isNull[row]) {
    writer.setNullAt(column);
  } else {
    BigDecimal v = ((DecimalColumnVector) vector).vector[row]
        .getHiveDecimal().bigDecimalValue();
    writer.write(column,
        new Decimal().set(new scala.math.BigDecimal(v), precision, scale),
        precision, scale);
  }
}
 
Example #2
Source File: SparkOrcReader.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public void convert(UnsafeArrayWriter writer, int element,
                    ColumnVector vector, int row) {
  if (vector.isRepeating) {
    row = 0;
  }
  if (!vector.noNulls && vector.isNull[row]) {
    writer.setNull(element);
  } else {
    BigDecimal v = ((DecimalColumnVector) vector).vector[row]
        .getHiveDecimal().bigDecimalValue();
    writer.write(element,
        new Decimal().set(new scala.math.BigDecimal(v), precision, scale),
        precision, scale);
  }
}
 
Example #3
Source File: GenericOrcWriter.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void addValue(int rowId, BigDecimal data, ColumnVector output) {
  // TODO: validate precision and scale from schema
  if (data == null) {
    output.noNulls = false;
    output.isNull[rowId] = true;
  } else {
    output.isNull[rowId] = false;
    ((DecimalColumnVector) output).vector[rowId]
        .setFromLongAndScale(data.unscaledValue().longValueExact(), scale);
  }
}
 
Example #4
Source File: GenericOrcWriter.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void addValue(int rowId, BigDecimal data, ColumnVector output) {
  // TODO: validate precision and scale from schema
  if (data == null) {
    output.noNulls = false;
    output.isNull[rowId] = true;
  } else {
    output.isNull[rowId] = false;
    ((DecimalColumnVector) output).vector[rowId].set(HiveDecimal.create(data, false));
  }
}
 
Example #5
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void addValue(int rowId, int column, SpecializedGetters data,
                     ColumnVector output) {
  if (data.isNullAt(column)) {
    output.noNulls = false;
    output.isNull[rowId] = true;
  } else {
    output.isNull[rowId] = false;
    ((DecimalColumnVector) output).vector[rowId].setFromLongAndScale(
        data.getDecimal(column, precision, scale).toUnscaledLong(), scale);
  }
}
 
Example #6
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void addValue(int rowId, int column, SpecializedGetters data,
                     ColumnVector output) {
  if (data.isNullAt(column)) {
    output.noNulls = false;
    output.isNull[rowId] = true;
  } else {
    output.isNull[rowId] = false;
    ((DecimalColumnVector) output).vector[rowId].set(
        HiveDecimal.create(data.getDecimal(column, precision, scale)
            .toJavaBigDecimal()));
  }
}
 
Example #7
Source File: SparkOrcReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void convert(UnsafeRowWriter writer, int column, ColumnVector vector,
                    int row) {
  if (vector.isRepeating) {
    row = 0;
  }
  if (!vector.noNulls && vector.isNull[row]) {
    writer.setNullAt(column);
  } else {
    HiveDecimalWritable v = ((DecimalColumnVector) vector).vector[row];
    writer.write(column,
        new Decimal().set(hack.unscaledLong(v), precision, v.scale()),
        precision, scale);
  }
}
 
Example #8
Source File: SparkOrcReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void convert(UnsafeArrayWriter writer, int element,
                    ColumnVector vector, int row) {
  if (vector.isRepeating) {
    row = 0;
  }
  if (!vector.noNulls && vector.isNull[row]) {
    writer.setNull(element);
  } else {
    HiveDecimalWritable v = ((DecimalColumnVector) vector).vector[row];
    writer.write(element,
        new Decimal().set(hack.unscaledLong(v), precision, v.scale()),
        precision, scale);
  }
}
 
Example #9
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 5 votes vote down vote up
public void addValue(int rowId, int column, SpecializedGetters data,
                     ColumnVector output) {
  if (data.isNullAt(column)) {
    output.noNulls = false;
    output.isNull[rowId] = true;
  } else {
    output.isNull[rowId] = false;
    ((DecimalColumnVector) output).vector[rowId].setFromLongAndScale(
        data.getDecimal(column, precision, scale).toUnscaledLong(), scale);
  }
}
 
Example #10
Source File: SparkOrcWriter.java    From iceberg with Apache License 2.0 5 votes vote down vote up
public void addValue(int rowId, int column, SpecializedGetters data,
                     ColumnVector output) {
  if (data.isNullAt(column)) {
    output.noNulls = false;
    output.isNull[rowId] = true;
  } else {
    output.isNull[rowId] = false;
    ((DecimalColumnVector) output).vector[rowId].set(
        HiveDecimal.create(data.getDecimal(column, precision, scale)
            .toJavaBigDecimal()));
  }
}
 
Example #11
Source File: AbstractOrcNoHiveVector.java    From flink with Apache License 2.0 5 votes vote down vote up
private static DecimalColumnVector createDecimalVector(int batchSize, int precision, int scale, Object value) {
	DecimalColumnVector dv = new DecimalColumnVector(batchSize, precision, scale);
	if (value == null) {
		dv.noNulls = false;
		dv.isNull[0] = true;
		dv.isRepeating = true;
	} else {
		dv.set(0, value instanceof HiveDecimal ?
				(HiveDecimal) value :
				HiveDecimal.create((BigDecimal) value));
		dv.isRepeating = true;
		dv.isNull[0] = false;
	}
	return dv;
}
 
Example #12
Source File: GenericOrcReaders.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
public BigDecimal nonNullRead(ColumnVector vector, int row) {
  DecimalColumnVector cv = (DecimalColumnVector) vector;
  return cv.vector[row].getHiveDecimal().bigDecimalValue().setScale(cv.scale);
}
 
Example #13
Source File: SparkOrcValueReaders.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
public Decimal nonNullRead(ColumnVector vector, int row) {
  HiveDecimalWritable value = ((DecimalColumnVector) vector).vector[row];
  return new Decimal().set(value.serialize64(value.scale()), value.precision(), value.scale());
}
 
Example #14
Source File: SparkOrcValueReaders.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
public Decimal nonNullRead(ColumnVector vector, int row) {
  BigDecimal value = ((DecimalColumnVector) vector).vector[row]
      .getHiveDecimal().bigDecimalValue();
  return new Decimal().set(new scala.math.BigDecimal(value), precision, scale);
}
 
Example #15
Source File: OrcNoHiveDecimalVector.java    From flink with Apache License 2.0 4 votes vote down vote up
public OrcNoHiveDecimalVector(DecimalColumnVector vector) {
	super(vector);
	this.vector = vector;
}