constantType(binder, elementType).invoke("createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(stackTypes.size()))); body.append(createBlockBuilder); Variable argument = scope.getVariable("arg" + i); IfStatement ifStatement = new IfStatement() .condition(equal(argument, constantNull(stackTypes.get(i)))) .ifTrue(blockBuilderVariable.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, elementType).writeValue(blockBuilderVariable, argument.cast(elementType.getJavaType())));
if (!getOnlyElement(fields).isPrimitiveType()) { serializerBody.append(new IfStatement() .condition(equal(fieldValue, constantNull(getter.getReturnType()))) .ifTrue(out.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(sqlType.writeValue(out, fieldValue))); serializerBody.append(fieldValue.set(state.cast(getter.getDeclaringClass()).invoke(getter))); if (!field.isPrimitiveType()) { serializerBody.append(new IfStatement().condition(equal(fieldValue, constantNull(getter.getReturnType()))) .ifTrue(rowBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(sqlType.writeValue(rowBuilder, fieldValue)));
"createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(1)))); body.append(singleRowBlockWriter.set(blockBuilder.invoke("beginBlockEntry", BlockBuilder.class)));
deserializerBody.append(new IfStatement() .condition(block.invoke("isNull", boolean.class, index)) .ifTrue(state.cast(setter.getDeclaringClass()).invoke(setter, constantNull(field.getType()))) .ifFalse(state.cast(setter.getDeclaringClass()).invoke(setter, constantType(binder, field.getSqlType()).getValue(block, index)))); deserializerBody.append(new IfStatement() .condition(row.invoke("isNull", boolean.class, constantInt(position))) .ifTrue(state.cast(setter.getDeclaringClass()).invoke(setter, constantNull(field.getType()))) .ifFalse(state.cast(setter.getDeclaringClass()).invoke(setter, constantType(binder, field.getSqlType()).getValue(row, constantInt(position)))));
body.append(blockBuilder.set(constantType(binder, toType).invoke("createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), array.invoke("getPositionCount", int.class))));
"createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(1)))); block.append(singleRowBlockWriter.set(blockBuilder.invoke("beginBlockEntry", BlockBuilder.class)));
ifStatement.condition(notEqual(hashChannel, constantNull(hashChannelField.getType()))); ifStatement.ifTrue( bigintType.invoke(
.ifFalse(thisVariable.setField( hashChannelField, constantNull(hashChannelField.getType())))); constructor.ret();
loadInputElement = new IfStatement() .condition(block.invoke("isNull", boolean.class, position)) .ifTrue(inputElement.set(constantNull(inputJavaType))) .ifFalse(inputElement.set(constantType(binder, inputType).getValue(block, position).cast(inputJavaType))); loadInputElement = new BytecodeBlock().append(inputElement.set(constantNull(inputJavaType))); if (!outputType.equals(UNKNOWN)) { writeOutputElement = new IfStatement() .condition(equal(outputElement, constantNull(outputJavaType))) .ifTrue(blockBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, outputType).writeValue(blockBuilder, outputElement.cast(outputType.getJavaType())));
loadKeyElement = new BytecodeBlock().append(keyElement.set(constantNull(keyJavaType))); loadValueElement = new IfStatement() .condition(block.invoke("isNull", boolean.class, add(position, constantInt(1)))) .ifTrue(valueElement.set(constantNull(valueJavaType))) .ifFalse(valueElement.set(valueSqlType.getValue(block, add(position, constantInt(1))).cast(valueJavaType))); loadValueElement = new BytecodeBlock().append(valueElement.set(constantNull(valueJavaType))); .append(keep.set(function.invoke("apply", Object.class, keyElement.cast(Object.class), valueElement.cast(Object.class)).cast(Boolean.class))) .append(new IfStatement("if (keep != null && keep) ...") .condition(and(notEqual(keep, constantNull(Boolean.class)), keep.cast(boolean.class))) .ifTrue(new BytecodeBlock() .append(keySqlType.invoke("appendTo", void.class, block, position, singleMapBlockWriter))
.append(keyElement.set(constantNull(keyJavaType))) .append(throwNullKeyException); loadValueElement = new IfStatement() .condition(block.invoke("isNull", boolean.class, add(position, constantInt(1)))) .ifTrue(valueElement.set(constantNull(valueJavaType))) .ifFalse(valueElement.set(valueSqlType.getValue(block, add(position, constantInt(1))).cast(valueJavaType))); loadValueElement = new BytecodeBlock().append(valueElement.set(constantNull(valueJavaType))); if (!transformedValueType.equals(UNKNOWN)) { writeTransformedValueElement = new IfStatement() .condition(equal(transformedValueElement, constantNull(transformedValueJavaType))) .ifTrue(blockBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, transformedValueType).writeValue(blockBuilder, transformedValueElement.cast(transformedValueType.getJavaType())));
.append(keyElement.set(constantNull(keyJavaType))) .append(throwNullKeyException); loadValueElement = new IfStatement() .condition(block.invoke("isNull", boolean.class, add(position, constantInt(1)))) .ifTrue(valueElement.set(constantNull(valueJavaType))) .ifFalse(valueElement.set(valueSqlType.getValue(block, add(position, constantInt(1))).cast(valueJavaType))); loadValueElement = new BytecodeBlock().append(valueElement.set(constantNull(valueJavaType))); .append(transformedKeyElement.set(function.invoke("apply", Object.class, keyElement.cast(Object.class), valueElement.cast(Object.class)).cast(transformedKeyJavaType))) .append(new IfStatement() .condition(equal(transformedKeyElement, constantNull(transformedKeyJavaType))) .ifTrue(throwNullKeyException) .ifFalse(new BytecodeBlock()
.append(thisVariable.setField(selectedPositionsField, selectedPositions)) .append(thisVariable.setField(nextIndexOrPositionField, selectedPositions.invoke("getOffset", int.class))) .append(thisVariable.setField(resultField, constantNull(Block.class)));
public static BytecodeExpression isNull(BytecodeExpression value) { return equal(value, constantNull(value.getType())); }
public static BytecodeExpression isNotNull(BytecodeExpression value) { return notEqual(value, constantNull(value.getType())); }
public static BytecodeExpression defaultValue(ParameterizedType type) { if (type.isPrimitive()) { return defaultValue(type.getPrimitiveType()); } return constantNull(type); }
public static BytecodeExpression defaultValue(Class<?> type) { requireNonNull(type, "type is null"); if (type == boolean.class) { return constantInt(0).cast(boolean.class); } if (type == byte.class) { return constantInt(0).cast(byte.class); } if (type == int.class) { return constantInt(0); } if (type == short.class) { return constantInt(0).cast(short.class); } if (type == long.class) { return constantLong(0L); } if (type == float.class) { return constantFloat(0.0f); } if (type == double.class) { return constantDouble(0.0d); } checkArgument(!type.isPrimitive(), "Unsupported type %s", type); return constantNull(type); }
@Test public void testNewArrayPrefilled() throws Exception { assertBytecodeExpressionType(newArray(type(boolean[].class), ImmutableList.of(constantTrue(), constantFalse(), constantTrue())), type(boolean[].class)); assertBytecodeExpression( newArray(type(boolean[].class), ImmutableList.of(constantTrue(), constantFalse(), constantTrue())), new boolean[] {true, false, true}, "new boolean[] {true, false, true}"); assertBytecodeExpressionType(newArray(type(int[].class), ImmutableList.of(constantInt(65), constantInt(66), constantInt(99))), type(int[].class)); assertBytecodeExpression( newArray(type(int[].class), ImmutableList.of(constantInt(65), constantInt(66), constantInt(99))), new int[] {65, 66, 99}, "new int[] {65, 66, 99}"); assertBytecodeExpressionType(newArray(type(long[].class), ImmutableList.of(constantLong(1234L), constantLong(12345L), constantLong(9876543210L))), type(long[].class)); assertBytecodeExpression( newArray(type(long[].class), ImmutableList.of(constantLong(1234L), constantLong(12345L), constantLong(9876543210L))), new long[] {1234L, 12345L, 9876543210L}, "new long[] {1234L, 12345L, 9876543210L}"); assertBytecodeExpressionType(newArray(type(String[].class), ImmutableList.of(constantString("grape"), constantNull(String.class), constantString("new"), constantString("array"))), type(String[].class)); assertBytecodeExpression( newArray(type(String[].class), ImmutableList.of(constantString("grape"), constantNull(String.class), constantString("new"), constantString("array"))), new String[] {"grape", null, "new", "array"}, "new String[] {\"grape\", null, \"new\", \"array\"}"); }
"createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(1)))); block.append(singleRowBlockWriter.set(blockBuilder.invoke("beginBlockEntry", BlockBuilder.class)));
.append(thisVariable.setField(selectedPositionsField, selectedPositions)) .append(thisVariable.setField(nextIndexOrPositionField, selectedPositions.invoke("getOffset", int.class))) .append(thisVariable.setField(resultField, constantNull(Block.class)));