List of usage examples for org.apache.spark.unsafe.types UTF8String getBytes
public byte[] getBytes()
From source file:com.github.sadikovi.riff.column.UTF8ColumnFilter.java
License:Open Source License
@Override public boolean mightContain(UTF8String value) { if (value == null) return hasNulls(); return filter.mightContainBinary(value.getBytes()); }
From source file:com.github.sadikovi.riff.stats.UTF8Statistics.java
License:Open Source License
/** * Return deep copy of UTF8String, this method forcefully copies `getBytes()` bytes in * UTF8String, since it does not return copy when backed by single array. * Clone is null safe, and would return null for null input. * @param str UTF8 string to clone/*from w w w. j a va 2 s. com*/ * @return copy */ private UTF8String clone(UTF8String str) { if (str == null) return null; byte[] bytes = new byte[str.numBytes()]; System.arraycopy(str.getBytes(), 0, bytes, 0, bytes.length); return UTF8String.fromBytes(bytes); }
From source file:org.apache.carbondata.streaming.CarbonStreamRecordReader.java
License:Apache License
private void putRowToColumnBatch(int rowId) { for (int i = 0; i < projection.length; i++) { Object value = outputValues[i]; ColumnVector col = columnarBatch.column(i); org.apache.spark.sql.types.DataType t = col.dataType(); if (null == value) { col.putNull(rowId);//from w w w.j av a2 s. co m } else { if (t == org.apache.spark.sql.types.DataTypes.BooleanType) { col.putBoolean(rowId, (boolean) value); } else if (t == org.apache.spark.sql.types.DataTypes.ByteType) { col.putByte(rowId, (byte) value); } else if (t == org.apache.spark.sql.types.DataTypes.ShortType) { col.putShort(rowId, (short) value); } else if (t == org.apache.spark.sql.types.DataTypes.IntegerType) { col.putInt(rowId, (int) value); } else if (t == org.apache.spark.sql.types.DataTypes.LongType) { col.putLong(rowId, (long) value); } else if (t == org.apache.spark.sql.types.DataTypes.FloatType) { col.putFloat(rowId, (float) value); } else if (t == org.apache.spark.sql.types.DataTypes.DoubleType) { col.putDouble(rowId, (double) value); } else if (t == org.apache.spark.sql.types.DataTypes.StringType) { UTF8String v = (UTF8String) value; col.putByteArray(rowId, v.getBytes()); } else if (t instanceof org.apache.spark.sql.types.DecimalType) { DecimalType dt = (DecimalType) t; Decimal d = Decimal.fromDecimal(value); if (dt.precision() <= Decimal.MAX_INT_DIGITS()) { col.putInt(rowId, (int) d.toUnscaledLong()); } else if (dt.precision() <= Decimal.MAX_LONG_DIGITS()) { col.putLong(rowId, d.toUnscaledLong()); } else { final BigInteger integer = d.toJavaBigDecimal().unscaledValue(); byte[] bytes = integer.toByteArray(); col.putByteArray(rowId, bytes, 0, bytes.length); } } else if (t instanceof CalendarIntervalType) { CalendarInterval c = (CalendarInterval) value; col.getChildColumn(0).putInt(rowId, c.months); col.getChildColumn(1).putLong(rowId, c.microseconds); } else if (t instanceof org.apache.spark.sql.types.DateType) { col.putInt(rowId, (int) value); } else if (t instanceof org.apache.spark.sql.types.TimestampType) { col.putLong(rowId, (long) value); } } } }