use of io.trino.spi.type.BigintType in project trino by trinodb.
the class JoinCompiler method generateHashPositionMethod.
private void generateHashPositionMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes, List<FieldDefinition> joinChannelFields, FieldDefinition hashChannelField) {
Parameter blockIndex = arg("blockIndex", int.class);
Parameter blockPosition = arg("blockPosition", int.class);
MethodDefinition hashPositionMethod = classDefinition.declareMethod(a(PUBLIC), "hashPosition", type(long.class), blockIndex, blockPosition);
Variable thisVariable = hashPositionMethod.getThis();
BytecodeExpression hashChannel = thisVariable.getField(hashChannelField);
BytecodeExpression bigintType = constantType(callSiteBinder, BigintType.BIGINT);
IfStatement ifStatement = new IfStatement();
ifStatement.condition(notEqual(hashChannel, constantNull(hashChannelField.getType())));
ifStatement.ifTrue(bigintType.invoke("getLong", long.class, hashChannel.invoke("get", Object.class, blockIndex).cast(Block.class), blockPosition).ret());
hashPositionMethod.getBody().append(ifStatement);
Variable resultVariable = hashPositionMethod.getScope().declareVariable(long.class, "result");
hashPositionMethod.getBody().push(0L).putVariable(resultVariable);
for (int index = 0; index < joinChannelTypes.size(); index++) {
Type type = joinChannelTypes.get(index);
BytecodeExpression block = hashPositionMethod.getThis().getField(joinChannelFields.get(index)).invoke("get", Object.class, blockIndex).cast(Block.class);
hashPositionMethod.getBody().getVariable(resultVariable).push(31L).append(OpCode.LMUL).append(typeHashCode(callSiteBinder, type, block, blockPosition)).append(OpCode.LADD).putVariable(resultVariable);
}
hashPositionMethod.getBody().getVariable(resultVariable).retLong();
}
use of io.trino.spi.type.BigintType in project trino by trinodb.
the class TestHiveBucketing method toNativeContainerValue.
private static Object toNativeContainerValue(Type type, Object hiveValue) {
if (hiveValue == null) {
return null;
}
if (type instanceof ArrayType) {
BlockBuilder blockBuilder = type.createBlockBuilder(null, 1);
BlockBuilder subBlockBuilder = blockBuilder.beginBlockEntry();
for (Object subElement : (Iterable<?>) hiveValue) {
appendToBlockBuilder(type.getTypeParameters().get(0), subElement, subBlockBuilder);
}
blockBuilder.closeEntry();
return type.getObject(blockBuilder, 0);
}
if (type instanceof RowType) {
BlockBuilder blockBuilder = type.createBlockBuilder(null, 1);
BlockBuilder subBlockBuilder = blockBuilder.beginBlockEntry();
int field = 0;
for (Object subElement : (Iterable<?>) hiveValue) {
appendToBlockBuilder(type.getTypeParameters().get(field), subElement, subBlockBuilder);
field++;
}
blockBuilder.closeEntry();
return type.getObject(blockBuilder, 0);
}
if (type instanceof MapType) {
BlockBuilder blockBuilder = type.createBlockBuilder(null, 1);
BlockBuilder subBlockBuilder = blockBuilder.beginBlockEntry();
for (Entry<?, ?> entry : ((Map<?, ?>) hiveValue).entrySet()) {
appendToBlockBuilder(type.getTypeParameters().get(0), entry.getKey(), subBlockBuilder);
appendToBlockBuilder(type.getTypeParameters().get(1), entry.getValue(), subBlockBuilder);
}
blockBuilder.closeEntry();
return type.getObject(blockBuilder, 0);
}
if (type instanceof BooleanType) {
return hiveValue;
}
if (type instanceof TinyintType) {
return (long) (byte) hiveValue;
}
if (type instanceof SmallintType) {
return (long) (short) hiveValue;
}
if (type instanceof IntegerType) {
return (long) (int) hiveValue;
}
if (type instanceof BigintType) {
return hiveValue;
}
if (type instanceof RealType) {
return (long) Float.floatToRawIntBits((float) hiveValue);
}
if (type instanceof DoubleType) {
return hiveValue;
}
if (type instanceof VarcharType) {
return Slices.utf8Slice(hiveValue.toString());
}
if (type instanceof DateType) {
return (long) ((Date) hiveValue).toEpochDay();
}
throw new IllegalArgumentException("Unsupported bucketing type: " + type);
}
Aggregations