use of io.prestosql.spi.block.IntArrayBlock in project hetu-core by openlookeng.
the class TestExpressionOptimizer method testCastWithJsonParseOptimization.
@Test
public void testCastWithJsonParseOptimization() {
FunctionHandle jsonParseFunctionHandle = functionAndTypeManager.lookupFunction("json_parse", fromTypes(VARCHAR));
// constant
FunctionHandle jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("array(integer)"));
RowExpression jsonCastExpression = new CallExpression(CAST.name(), jsonCastFunctionHandle, new ArrayType(INTEGER), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, constant(utf8Slice("[1, 2]"), VARCHAR))), Optional.empty());
RowExpression resultExpression = optimizer.optimize(jsonCastExpression);
assertInstanceOf(resultExpression, ConstantExpression.class);
Object resultValue = ((ConstantExpression) resultExpression).getValue();
assertInstanceOf(resultValue, IntArrayBlock.class);
assertEquals(toValues(INTEGER, (IntArrayBlock) resultValue), ImmutableList.of(1, 2));
// varchar to array
jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("array(varchar)"));
jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, new ArrayType(VARCHAR), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
resultExpression = optimizer.optimize(jsonCastExpression);
assertEquals(resultExpression, call(JSON_TO_ARRAY_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_ARRAY_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("array(varchar)")), new ArrayType(VARCHAR), field(1, VARCHAR)));
// varchar to row
jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("row(varchar,bigint)"));
jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, RowType.anonymous(ImmutableList.of(VARCHAR, BIGINT)), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
resultExpression = optimizer.optimize(jsonCastExpression);
assertEquals(resultExpression, call(JSON_TO_ROW_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_ROW_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("row(varchar,bigint)")), RowType.anonymous(ImmutableList.of(VARCHAR, BIGINT)), field(1, VARCHAR)));
// varchar to map
jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("map(integer,varchar)"));
jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, mapType(INTEGER, VARCHAR), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
resultExpression = optimizer.optimize(jsonCastExpression);
assertEquals(resultExpression, call(JSON_TO_MAP_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_MAP_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("map(integer, varchar)")), mapType(INTEGER, VARCHAR), field(1, VARCHAR)));
}
use of io.prestosql.spi.block.IntArrayBlock in project hetu-core by openlookeng.
the class FloatSelectiveColumnReader method getBlock.
@Override
public Block getBlock(int[] positions, int positionCount) {
checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
checkState(outputRequired, "This stream reader doesn't produce output");
checkState(positionCount <= outputPositionCount, "Not enough values");
if (allNulls) {
return new RunLengthEncodedBlock(NULL_BLOCK, positionCount);
}
boolean includeNulls = nullsAllowed && presentStream != null;
if (positionCount == outputPositionCount) {
Block block = new IntArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values);
nulls = null;
values = null;
return block;
}
int[] valuesCopy = new int[positionCount];
boolean[] nullsCopy = null;
if (includeNulls) {
nullsCopy = new boolean[positionCount];
}
int positionIndex = 0;
int nextPosition = positions[positionIndex];
for (int i = 0; i < outputPositionCount; i++) {
if (outputPositions[i] < nextPosition) {
continue;
}
valuesCopy[positionIndex] = this.values[i];
if (nullsCopy != null) {
nullsCopy[positionIndex] = this.nulls[i];
}
positionIndex++;
if (positionIndex >= positionCount) {
break;
}
nextPosition = positions[positionIndex];
}
return new IntArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
use of io.prestosql.spi.block.IntArrayBlock in project hetu-core by openlookeng.
the class TestHBase method testPageSink.
/**
* testPageSink
*/
@Test
public void testPageSink() {
HBasePageSinkProvider hpsp = new HBasePageSinkProvider(hconn);
HBaseTableHandle insertHandler = new HBaseTableHandle("hbase", "test_table", 0, hconn.getTable("hbase.test_table").getColumns(), hconn.getTable("hbase.test_table").getSerializerClassName(), Optional.of("test_table"), OptionalLong.empty());
if (insertHandler instanceof ConnectorInsertTableHandle) {
ConnectorPageSink cps = hpsp.createPageSink(new HBaseTransactionHandle(), session, (ConnectorInsertTableHandle) insertHandler);
long completedBytes = cps.getCompletedBytes();
long sysMemUsage = cps.getSystemMemoryUsage();
long cpuNanos = cps.getValidationCpuNanos();
assertTrue(cpuNanos >= 0);
assertTrue(sysMemUsage >= 0);
assertTrue(completedBytes >= 0);
int[] offsets = { 0, 4 };
Block rowkey = new VariableWidthBlock(1, TestSliceUtils.createSlice("0001"), offsets, Optional.empty());
int[] offset2 = { 0, 5 };
Block name = new VariableWidthBlock(1, TestSliceUtils.createSlice("name2"), offset2, Optional.empty());
long[] longs = new long[1];
longs[0] = 12;
Block age = new LongArrayBlock(1, Optional.empty(), longs);
int[] ints = new int[1];
ints[0] = 17832;
Block gender = new IntArrayBlock(1, Optional.empty(), ints);
Block columnT = new LongArrayBlock(1, Optional.empty(), longs);
Page page = new Page(rowkey, name, age, gender, columnT);
assertEquals(NOT_BLOCKED, cps.appendPage(page));
cps.abort();
}
}
use of io.prestosql.spi.block.IntArrayBlock in project hetu-core by openlookeng.
the class TestHetuObjectTranslator method testTranslateFromHiveObjectWithListObject.
@Test
public void testTranslateFromHiveObjectWithListObject() {
Object res = new IntArrayBlock(2, Optional.ofNullable(new boolean[] { true, true }), new int[] { 1, 2 });
assertEquals(translateFromHiveObject(new ArrayParametricType().createType(Arrays.asList("integer")), Arrays.asList(1, 2)).toString(), res.toString());
}
use of io.prestosql.spi.block.IntArrayBlock in project hetu-core by openlookeng.
the class TestHetuObjectTranslator method testTranslateToHiveObjectWithListObject.
@Test
public void testTranslateToHiveObjectWithListObject() {
ParameterizedType listType = new ParameterizedType() {
@Override
public Type[] getActualTypeArguments() {
return new Type[] { Integer.class };
}
@Override
public Type getRawType() {
return List.class;
}
@Override
public Type getOwnerType() {
return null;
}
};
Object obj = new IntArrayBlock(2, Optional.ofNullable(new boolean[] { true, true }), new int[] { 1, 2 });
assertEquals(translateToHiveObject(new ArrayParametricType().createType(Arrays.asList("integer")), obj, listType), Arrays.asList(1, 2));
}
Aggregations