Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private static MethodHandle generateTransform(Type inputType, Type outputType)

private static MethodDefinition generateTransformValueInner(ClassDefinition definition, CallSiteBinder binder, Type inputType, Type outputType)
{
Class<?> inputJavaType = Primitives.wrap(inputType.getJavaType());
Class<?> outputJavaType = Primitives.wrap(outputType.getJavaType());
Class<?> inputJavaType = binder.getAccessibleType(Primitives.wrap(inputType.getJavaType()));
Class<?> outputJavaType = binder.getAccessibleType(Primitives.wrap(outputType.getJavaType()));

Parameter block = arg("block", Block.class);
Parameter function = arg("function", UnaryFunctionInterface.class);
Expand Down Expand Up @@ -190,7 +190,7 @@ private static MethodDefinition generateTransformValueInner(ClassDefinition defi
writeOutputElement = new IfStatement()
.condition(equal(outputElement, constantNull(outputJavaType)))
.ifTrue(elementBuilder.invoke("appendNull", BlockBuilder.class).pop())
.ifFalse(constantType(binder, outputType).writeValue(elementBuilder, outputElement.cast(outputType.getJavaType())));
.ifFalse(constantType(binder, outputType).writeValue(elementBuilder, outputElement.cast(outputJavaType)));
}
else {
writeOutputElement = new BytecodeBlock().append(elementBuilder.invoke("appendNull", BlockBuilder.class).pop());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ private static MethodDefinition generateFilterInner(ClassDefinition definition,

Type keyType = mapType.getKeyType();
Type valueType = mapType.getValueType();
Class<?> keyJavaType = Primitives.wrap(keyType.getJavaType());
Class<?> valueJavaType = Primitives.wrap(valueType.getJavaType());
Class<?> keyJavaType = binder.getAccessibleType(Primitives.wrap(keyType.getJavaType()));
Class<?> valueJavaType = binder.getAccessibleType(Primitives.wrap(valueType.getJavaType()));

Variable size = scope.declareVariable("size", body, map.invoke("getSize", int.class));
Variable rawOffset = scope.declareVariable("rawOffset", body, map.invoke("getRawOffset", int.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ private static MethodDefinition generateTransformKeyInner(ClassDefinition defini
BytecodeBlock body = method.getBody();
Scope scope = method.getScope();

Class<?> keyJavaType = Primitives.wrap(keyType.getJavaType());
Class<?> transformedKeyJavaType = Primitives.wrap(transformedKeyType.getJavaType());
Class<?> valueJavaType = Primitives.wrap(valueType.getJavaType());
Class<?> keyJavaType = binder.getAccessibleType(Primitives.wrap(keyType.getJavaType()));
Class<?> transformedKeyJavaType = binder.getAccessibleType(Primitives.wrap(transformedKeyType.getJavaType()));
Class<?> valueJavaType = binder.getAccessibleType(Primitives.wrap(valueType.getJavaType()));

Variable size = scope.declareVariable("size", body, map.invoke("getSize", int.class));
Variable rawOffset = scope.declareVariable("rawOffset", body, map.invoke("getRawOffset", int.class));
Expand Down Expand Up @@ -243,7 +243,7 @@ private static MethodDefinition generateTransformKeyInner(ClassDefinition defini
.condition(equal(transformedKeyElement, constantNull(transformedKeyJavaType)))
.ifTrue(throwNullKeyException)
.ifFalse(new BytecodeBlock()
.append(constantType(binder, transformedKeyType).writeValue(keyBuilder, transformedKeyElement.cast(transformedKeyType.getJavaType())))
.append(constantType(binder, transformedKeyType).writeValue(keyBuilder, transformedKeyElement.cast(transformedKeyJavaType)))
.append(valueBuilder.invoke(
"append",
void.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ private static MethodDefinition generateTransformInner(ClassDefinition definitio
BytecodeBlock body = method.getBody();
Scope scope = method.getScope();

Class<?> keyJavaType = Primitives.wrap(keyType.getJavaType());
Class<?> valueJavaType = Primitives.wrap(valueType.getJavaType());
Class<?> transformedValueJavaType = Primitives.wrap(transformedValueType.getJavaType());
Class<?> keyJavaType = binder.getAccessibleType(Primitives.wrap(keyType.getJavaType()));
Class<?> valueJavaType = binder.getAccessibleType(Primitives.wrap(valueType.getJavaType()));
Class<?> transformedValueJavaType = binder.getAccessibleType(Primitives.wrap(transformedValueType.getJavaType()));

Variable size = scope.declareVariable("size", body, map.invoke("getSize", int.class));
Variable rawOffset = scope.declareVariable("rawOffset", body, map.invoke("getRawOffset", int.class));
Expand Down Expand Up @@ -227,7 +227,7 @@ private static MethodDefinition generateTransformInner(ClassDefinition definitio
writeTransformedValueElement = new IfStatement()
.condition(equal(transformedValueElement, constantNull(transformedValueJavaType)))
.ifTrue(valueBuilder.invoke("appendNull", BlockBuilder.class).pop())
.ifFalse(constantType(binder, transformedValueType).writeValue(valueBuilder, transformedValueElement.cast(transformedValueType.getJavaType())));
.ifFalse(constantType(binder, transformedValueType).writeValue(valueBuilder, transformedValueElement.cast(transformedValueJavaType)));
}
else {
writeTransformedValueElement = valueBuilder.invoke("appendNull", BlockBuilder.class).pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generator)

ifWasNull.ifTrue()
.comment("clear the null flag, pop residual value off stack, and push was null flag on the stack (true)")
.pop(term.type().getJavaType()) // discard residual value
.pop(generator.getCallSiteBinder().getAccessibleType(term.type().getJavaType())) // discard residual value
.pop(boolean.class) // discard the previous "we've seen a null flag"
.push(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext context)
Variable blockBuilder = scope.getOrCreateTempVariable(BlockBuilder.class);
block.append(blockBuilder.set(constantType(binder, elementType).invoke("createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(elements.size()))));

Variable element = scope.getOrCreateTempVariable(elementType.getJavaType());
Variable element = scope.getOrCreateTempVariable(binder.getAccessibleType(elementType.getJavaType()));

for (Expression item : elements) {
block.append(context.wasNull().set(constantFalse()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public ArrayMapBytecodeExpression(
mapperDescription = "null";
}
else {
Variable element = scope.declareVariable(fromType.getJavaType(), "element_" + NEXT_VARIABLE_ID.getAndIncrement());
Variable newElement = scope.declareVariable(toType.getJavaType(), "newElement_" + NEXT_VARIABLE_ID.getAndIncrement());
Variable element = scope.declareVariable(binder.getAccessibleType(fromType.getJavaType()), "element_" + NEXT_VARIABLE_ID.getAndIncrement());
Variable newElement = scope.declareVariable(binder.getAccessibleType(toType.getJavaType()), "newElement_" + NEXT_VARIABLE_ID.getAndIncrement());
SqlTypeBytecodeExpression elementTypeConstant = constantType(binder, fromType);
SqlTypeBytecodeExpression newElementTypeConstant = constantType(binder, toType);
mapElement = new BytecodeBlock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public BetweenCodeGenerator(Between between, Metadata metadata)
@Override
public BytecodeNode generateExpression(BytecodeGeneratorContext context)
{
Variable firstValue = context.getScope().getOrCreateTempVariable(value.type().getJavaType());
Class<?> valueJavaType = context.getCallSiteBinder().getAccessibleType(value.type().getJavaType());
Variable firstValue = context.getScope().getOrCreateTempVariable(valueJavaType);
Reference valueReference = createTempReference(firstValue, value.type());

Logical newExpression = new Logical(
Expand All @@ -68,7 +69,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext context)
BytecodeBlock block = new BytecodeBlock()
.comment("check if value is null")
.append(context.generate(value))
.append(ifWasNullPopAndGoto(context.getScope(), done, boolean.class, value.type().getJavaType()))
.append(ifWasNullPopAndGoto(context.getScope(), done, boolean.class, valueJavaType))
.putVariable(firstValue)
.append(context.generate(newExpression))
.visitLabel(done);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public CoalesceCodeGenerator(Coalesce coalesce)
@Override
public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext)
{
Class<?> returnJavaType = generatorContext.getCallSiteBinder().getAccessibleType(returnType.getJavaType());

List<BytecodeNode> operands = new ArrayList<>();
for (Expression expression : arguments) {
operands.add(generatorContext.generate(expression));
Expand All @@ -52,7 +54,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext
Variable wasNull = generatorContext.wasNull();
BytecodeNode nullValue = new BytecodeBlock()
.append(wasNull.set(constantTrue()))
.pushJavaDefault(returnType.getJavaType());
.pushJavaDefault(returnJavaType);

// reverse list because current if statement builder doesn't support if/else so we need to build the if statements bottom up
for (BytecodeNode operand : operands.reversed()) {
Expand All @@ -64,7 +66,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext

// if value was null, pop the null value, clear the null flag, and process the next operand
ifStatement.ifTrue()
.pop(returnType.getJavaType())
.pop(returnJavaType)
.append(wasNull.set(constantFalse()))
.append(nullValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generator)
IfStatement ifRowBlockIsNull = new IfStatement("if row block is null...")
.condition(wasNull);

Class<?> javaType = returnType.getJavaType();
Class<?> javaType = callSiteBinder.getAccessibleType(returnType.getJavaType());
LabelNode end = new LabelNode("end");
ifRowBlockIsNull.ifTrue()
.comment("if row block is null, push null to the stack and goto 'end' label (return)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ private InputReferenceNode(CallSiteBinder callSiteBinder, Scope scope, Type type

String methodName = "get" + Primitives.wrap(callType).getSimpleName();
BytecodeExpression value = constantType(callSiteBinder, type).invoke(methodName, callType, block, position);
if (callType != type.getJavaType()) {
value = value.cast(type.getJavaType());
Class<?> expectedType = callSiteBinder.getAccessibleType(type.getJavaType());
if (callType != expectedType) {
value = value.cast(expectedType);
}
ifStatement.ifFalse(value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext
BytecodeBlock block = new BytecodeBlock()
.comment("is null")
.append(value)
.pop(argument.type().getJavaType())
.pop(generatorContext.getCallSiteBinder().getAccessibleType(argument.type().getJavaType()))
.append(wasNull);

// clear the null flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static CompiledLambda preGenerateLambdaExpression(
parameters.add(arg("session", ConnectorSession.class));
for (int i = 0; i < lambdaExpression.arguments().size(); i++) {
Symbol argument = lambdaExpression.arguments().get(i);
Class<?> type = Primitives.wrap(argument.type().getJavaType());
Class<?> type = callSiteBinder.getAccessibleType(Primitives.wrap(argument.type().getJavaType()));
String argumentName = argument.name();
Parameter arg = arg("lambda_" + i + "_" + BytecodeUtils.sanitizeName(argumentName), type);
parameters.add(arg);
Expand All @@ -153,6 +153,7 @@ public static CompiledLambda preGenerateLambdaExpression(
classDefinition,
methodName,
parameters.build(),
callSiteBinder,
lambdaExpression);
}

Expand All @@ -161,10 +162,11 @@ private static CompiledLambda defineLambdaMethod(
ClassDefinition classDefinition,
String methodName,
List<Parameter> inputParameters,
CallSiteBinder callSiteBinder,
Lambda lambda)
{
checkCondition(inputParameters.size() <= 254, NOT_SUPPORTED, "Too many arguments for lambda expression");
Class<?> returnType = Primitives.wrap(lambda.body().type().getJavaType());
Class<?> returnType = callSiteBinder.getAccessibleType(Primitives.wrap(lambda.body().type().getJavaType()));
MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), methodName, type(returnType), inputParameters);

Scope scope = method.getScope();
Expand Down Expand Up @@ -209,7 +211,7 @@ public static BytecodeNode generateLambda(
ImmutableList.Builder<BytecodeExpression> captureVariableBuilder = ImmutableList.builderWithExpectedSize(captureExpressions.size());
List<Variable> captureTempVariables = new ArrayList<>(captureExpressions.size());
for (Expression captureExpression : captureExpressions) {
Class<?> valueType = Primitives.wrap(captureExpression.type().getJavaType());
Class<?> valueType = context.getCallSiteBinder().getAccessibleType(Primitives.wrap(captureExpression.type().getJavaType()));
Variable valueVariable = scope.getOrCreateTempVariable(valueType);
captureTempVariables.add(valueVariable);
block.append(context.generate(captureExpression));
Expand Down Expand Up @@ -296,7 +298,7 @@ public static Class<? extends Supplier<Object>> compileLambdaProvider(Lambda lam
parameters.add(arg("session", ConnectorSession.class));
for (int i = 0; i < lambdaExpression.arguments().size(); i++) {
Symbol argument = lambdaExpression.arguments().get(i);
Class<?> type = Primitives.wrap(argument.type().getJavaType());
Class<?> type = callSiteBinder.getAccessibleType(Primitives.wrap(argument.type().getJavaType()));
parameters.add(arg("lambda_" + i + "_" + BytecodeUtils.sanitizeName(argument.name()), type));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ private static Optional<ResolvedFunction> getCastIfNeeded(Metadata metadata, io.
public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext)
{
Scope scope = generatorContext.getScope();
Class<?> firstJavaType = generatorContext.getCallSiteBinder().getAccessibleType(first.type().getJavaType());

LabelNode notMatch = new LabelNode("notMatch");

// push first arg on the stack
Variable firstValue = scope.getOrCreateTempVariable(first.type().getJavaType());
Variable firstValue = scope.getOrCreateTempVariable(firstJavaType);
BytecodeBlock block = new BytecodeBlock()
.comment("check if first arg is null")
.append(generatorContext.generate(first))
.append(ifWasNullPopAndGoto(scope, notMatch, void.class))
.dup(first.type().getJavaType())
.dup(firstJavaType)
.putVariable(firstValue);

BytecodeNode secondValue = generatorContext.generate(second);
Expand All @@ -94,8 +95,8 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext
// if first and second are equal, return null
BytecodeBlock trueBlock = new BytecodeBlock()
.append(generatorContext.wasNull().set(constantTrue()))
.pop(first.type().getJavaType())
.pushJavaDefault(first.type().getJavaType());
.pop(firstJavaType)
.pushJavaDefault(firstJavaType);

// else return first (which is still on the stack
block.append(new IfStatement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext generator)

ifWasNull.ifTrue()
.comment("clear the null flag, pop residual value off stack, and push was null flag on the stack (true)")
.pop(term.type().getJavaType()) // discard residual value
.pop(generator.getCallSiteBinder().getAccessibleType(term.type().getJavaType())) // discard residual value
.pop(boolean.class) // discard the previous "we've seen a null flag"
.push(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public BytecodeNode generateExpression(BytecodeGeneratorContext context)
block.comment("Clean wasNull and Generate + " + i + "-th field of row");
block.append(context.wasNull().set(constantFalse()));
block.append(context.generate(arguments.get(i)));
Variable field = scope.getOrCreateTempVariable(fieldType.getJavaType());
Variable field = scope.getOrCreateTempVariable(binder.getAccessibleType(fieldType.getJavaType()));
block.putVariable(field);
block.append(new IfStatement()
.condition(context.wasNull())
Expand Down Expand Up @@ -181,7 +181,7 @@ private MethodDefinition generatePartialRowConstructor(int start, int end, Bytec

block.append(context.wasNull().set(constantFalse()));
block.append(context.generate(arguments.get(i)));
Variable field = scope.getOrCreateTempVariable(fieldType.getJavaType());
Variable field = scope.getOrCreateTempVariable(binder.getAccessibleType(fieldType.getJavaType()));
block.putVariable(field);
block.append(new IfStatement()
.condition(context.wasNull())
Expand Down
Loading