use of org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector in project hive by apache.
the class KuduSerDe method serialize.
/**
* Serialize an object by navigating inside the Object with the ObjectInspector.
*/
@Override
public KuduWritable serialize(Object obj, ObjectInspector objectInspector) throws SerDeException {
Preconditions.checkArgument(objectInspector.getCategory() == Category.STRUCT);
StructObjectInspector soi = (StructObjectInspector) objectInspector;
List<Object> writableObj = soi.getStructFieldsDataAsList(obj);
List<? extends StructField> fields = soi.getAllStructFieldRefs();
PartialRow row = schema.newPartialRow();
for (int i = 0; i < schema.getColumnCount(); i++) {
StructField field = fields.get(i);
Object value = writableObj.get(i);
if (value == null) {
row.setNull(i);
} else {
Type type = schema.getColumnByIndex(i).getType();
ObjectInspector inspector = field.getFieldObjectInspector();
switch(type) {
case BOOL:
boolean boolVal = ((BooleanObjectInspector) inspector).get(value);
row.addBoolean(i, boolVal);
break;
case INT8:
byte byteVal = ((ByteObjectInspector) inspector).get(value);
row.addByte(i, byteVal);
break;
case INT16:
short shortVal = ((ShortObjectInspector) inspector).get(value);
row.addShort(i, shortVal);
break;
case INT32:
int intVal = ((IntObjectInspector) inspector).get(value);
row.addInt(i, intVal);
break;
case INT64:
long longVal = ((LongObjectInspector) inspector).get(value);
row.addLong(i, longVal);
break;
case UNIXTIME_MICROS:
// Calling toSqlTimestamp and using the addTimestamp API ensures we properly
// convert Hive localDateTime to UTC.
java.sql.Timestamp timestampVal = ((TimestampObjectInspector) inspector).getPrimitiveJavaObject(value).toSqlTimestamp();
row.addTimestamp(i, timestampVal);
break;
case DECIMAL:
HiveDecimal decimalVal = ((HiveDecimalObjectInspector) inspector).getPrimitiveJavaObject(value);
row.addDecimal(i, decimalVal.bigDecimalValue());
break;
case FLOAT:
float floatVal = ((FloatObjectInspector) inspector).get(value);
row.addFloat(i, floatVal);
break;
case DOUBLE:
double doubleVal = ((DoubleObjectInspector) inspector).get(value);
row.addDouble(i, doubleVal);
break;
case STRING:
String stringVal = ((StringObjectInspector) inspector).getPrimitiveJavaObject(value);
row.addString(i, stringVal);
break;
case BINARY:
byte[] bytesVal = ((BinaryObjectInspector) inspector).getPrimitiveJavaObject(value);
row.addBinary(i, bytesVal);
break;
default:
throw new SerDeException("Unsupported column type: " + type.name());
}
}
}
return new KuduWritable(row);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector in project hive by apache.
the class FixAcidKeyIndex method validate.
public static AcidKeyIndexValidationResult validate(Configuration conf, Path inputPath) throws IOException {
AcidKeyIndexValidationResult result = new AcidKeyIndexValidationResult();
FileSystem fs = inputPath.getFileSystem(conf);
try (Reader reader = OrcFile.createReader(fs, inputPath);
RecordReader rr = reader.rows()) {
List<StripeInformation> stripes = reader.getStripes();
RecordIdentifier[] keyIndex = OrcRecordUpdater.parseKeyIndex(reader);
StructObjectInspector soi = (StructObjectInspector) reader.getObjectInspector();
// struct<operation:int,originalTransaction:bigint,bucket:int,rowId:bigint,currentTransaction:bigint
List<? extends StructField> structFields = soi.getAllStructFieldRefs();
StructField transactionField = structFields.get(1);
LongObjectInspector transactionOI = (LongObjectInspector) transactionField.getFieldObjectInspector();
StructField bucketField = structFields.get(2);
IntObjectInspector bucketOI = (IntObjectInspector) bucketField.getFieldObjectInspector();
StructField rowIdField = structFields.get(3);
LongObjectInspector rowIdOI = (LongObjectInspector) rowIdField.getFieldObjectInspector();
long rowsProcessed = 0;
for (int i = 0; i < stripes.size(); i++) {
rowsProcessed += stripes.get(i).getNumberOfRows();
rr.seekToRow(rowsProcessed - 1);
OrcStruct row = (OrcStruct) rr.next(null);
long lastTransaction = transactionOI.get(soi.getStructFieldData(row, transactionField));
int lastBucket = bucketOI.get(soi.getStructFieldData(row, bucketField));
long lastRowId = rowIdOI.get(soi.getStructFieldData(row, rowIdField));
RecordIdentifier recordIdentifier = new RecordIdentifier(lastTransaction, lastBucket, lastRowId);
result.recordIdentifiers.add(recordIdentifier);
if (stripes.size() != keyIndex.length || keyIndex[i] == null || recordIdentifier.compareTo(keyIndex[i]) != 0) {
result.isValid = false;
}
}
}
return result;
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector in project hive by apache.
the class GenericUDFInBloomFilter method evaluate.
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
// Return if either of the arguments is null
if (arguments[0].get() == null || arguments[1].get() == null) {
return null;
}
if (!initializedBloomFilter) {
// Setup the bloom filter once
InputStream in = null;
try {
BytesWritable bw = (BytesWritable) arguments[1].get();
byte[] bytes = new byte[bw.getLength()];
System.arraycopy(bw.getBytes(), 0, bytes, 0, bw.getLength());
in = new NonSyncByteArrayInputStream(bytes);
bloomFilter = BloomKFilter.deserialize(in);
} catch (IOException e) {
throw new HiveException(e);
} finally {
IOUtils.closeStream(in);
}
initializedBloomFilter = true;
}
// Check if the value is in bloom filter
switch(((PrimitiveObjectInspector) valObjectInspector).getTypeInfo().getPrimitiveCategory()) {
case BOOLEAN:
boolean vBoolean = ((BooleanObjectInspector) valObjectInspector).get(arguments[0].get());
return bloomFilter.testLong(vBoolean ? 1 : 0);
case BYTE:
byte vByte = ((ByteObjectInspector) valObjectInspector).get(arguments[0].get());
return bloomFilter.testLong(vByte);
case SHORT:
short vShort = ((ShortObjectInspector) valObjectInspector).get(arguments[0].get());
return bloomFilter.testLong(vShort);
case INT:
int vInt = ((IntObjectInspector) valObjectInspector).get(arguments[0].get());
return bloomFilter.testLong(vInt);
case LONG:
long vLong = ((LongObjectInspector) valObjectInspector).get(arguments[0].get());
return bloomFilter.testLong(vLong);
case FLOAT:
float vFloat = ((FloatObjectInspector) valObjectInspector).get(arguments[0].get());
return bloomFilter.testDouble(vFloat);
case DOUBLE:
double vDouble = ((DoubleObjectInspector) valObjectInspector).get(arguments[0].get());
return bloomFilter.testDouble(vDouble);
case DECIMAL:
HiveDecimalWritable vDecimal = ((HiveDecimalObjectInspector) valObjectInspector).getPrimitiveWritableObject(arguments[0].get());
int startIdx = vDecimal.toBytes(scratchBuffer);
return bloomFilter.testBytes(scratchBuffer, startIdx, scratchBuffer.length - startIdx);
case DATE:
DateWritableV2 vDate = ((DateObjectInspector) valObjectInspector).getPrimitiveWritableObject(arguments[0].get());
return bloomFilter.testLong(vDate.getDays());
case TIMESTAMP:
Timestamp vTimeStamp = ((TimestampObjectInspector) valObjectInspector).getPrimitiveJavaObject(arguments[0].get());
return bloomFilter.testLong(vTimeStamp.toEpochMilli());
case CHAR:
Text vChar = ((HiveCharObjectInspector) valObjectInspector).getPrimitiveWritableObject(arguments[0].get()).getStrippedValue();
return bloomFilter.testBytes(vChar.getBytes(), 0, vChar.getLength());
case VARCHAR:
Text vVarchar = ((HiveVarcharObjectInspector) valObjectInspector).getPrimitiveWritableObject(arguments[0].get()).getTextValue();
return bloomFilter.testBytes(vVarchar.getBytes(), 0, vVarchar.getLength());
case STRING:
Text vString = ((StringObjectInspector) valObjectInspector).getPrimitiveWritableObject(arguments[0].get());
return bloomFilter.testBytes(vString.getBytes(), 0, vString.getLength());
case BINARY:
BytesWritable vBytes = ((BinaryObjectInspector) valObjectInspector).getPrimitiveWritableObject(arguments[0].get());
return bloomFilter.testBytes(vBytes.getBytes(), 0, vBytes.getLength());
default:
throw new UDFArgumentTypeException(0, "Bad primitive category " + ((PrimitiveTypeInfo) valObjectInspector).getPrimitiveCategory());
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector in project hive by apache.
the class GenericUDFFromUnixTime method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
checkArgsSize(arguments, 1, 2);
for (int i = 0; i < arguments.length; i++) {
checkArgPrimitive(arguments, i);
}
PrimitiveObjectInspector arg0OI = (PrimitiveObjectInspector) arguments[0];
switch(arg0OI.getPrimitiveCategory()) {
case INT:
inputIntOI = (IntObjectInspector) arguments[0];
break;
case LONG:
inputLongOI = (LongObjectInspector) arguments[0];
break;
default:
throw new UDFArgumentException("The function from_unixtime takes only int/long types for first argument. Got Type:" + arg0OI.getPrimitiveCategory().name());
}
if (arguments.length == 2) {
checkArgGroups(arguments, 1, inputTypes, STRING_GROUP);
obtainStringConverter(arguments, 1, inputTypes, converters);
}
if (timeZone == null) {
timeZone = SessionState.get() == null ? new HiveConf().getLocalTimeZone() : SessionState.get().getConf().getLocalTimeZone();
FORMATTER.withZone(timeZone);
}
return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector in project hive by apache.
the class ColumnStatisticsObjTranslator method unpackTimestampStats.
private static void unpackTimestampStats(ObjectInspector oi, Object o, ColumnStatsField csf, ColumnStatisticsObj statsObj) {
switch(csf) {
case COUNT_NULLS:
long cn = ((LongObjectInspector) oi).get(o);
statsObj.getStatsData().getTimestampStats().setNumNulls(cn);
break;
case MIN:
TimestampWritableV2 min = ((TimestampObjectInspector) oi).getPrimitiveWritableObject(o);
statsObj.getStatsData().getTimestampStats().setLowValue(new Timestamp(min.getSeconds()));
break;
case MAX:
TimestampWritableV2 max = ((TimestampObjectInspector) oi).getPrimitiveWritableObject(o);
statsObj.getStatsData().getTimestampStats().setHighValue(new Timestamp(max.getSeconds()));
break;
case NDV:
long ndv = ((LongObjectInspector) oi).get(o);
statsObj.getStatsData().getTimestampStats().setNumDVs(ndv);
break;
case BITVECTOR:
PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
byte[] buf = ((BinaryObjectInspector) poi).getPrimitiveJavaObject(o);
statsObj.getStatsData().getTimestampStats().setBitVectors(buf);
break;
default:
throw new RuntimeException("Unsupported column stat for TIMESTAMP : " + csf);
}
}
Aggregations