use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestShardCompactor method extractColumns.
private static MaterializedResult extractColumns(MaterializedResult materializedRows, List<Integer> indexes, List<Type> types) {
ImmutableList.Builder<MaterializedRow> rows = ImmutableList.builder();
for (MaterializedRow row : materializedRows) {
Object[] values = new Object[indexes.size()];
for (int i = 0; i < indexes.size(); i++) {
values[i] = row.getField(indexes.get(i));
}
rows.add(new MaterializedRow(MaterializedResult.DEFAULT_PRECISION, values));
}
return new MaterializedResult(rows.build(), types);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestShardMetadataRecordCursor method testSimple.
@Test
public void testSimple() {
ShardManager shardManager = createShardManager(dbi);
// Add shards to the table
long tableId = 1;
OptionalInt bucketNumber = OptionalInt.empty();
UUID uuid1 = UUID.randomUUID();
UUID uuid2 = UUID.randomUUID();
UUID uuid3 = UUID.randomUUID();
ShardInfo shardInfo1 = new ShardInfo(uuid1, bucketNumber, ImmutableSet.of("node1"), ImmutableList.of(), 1, 10, 100, 0x1234);
ShardInfo shardInfo2 = new ShardInfo(uuid2, bucketNumber, ImmutableSet.of("node2"), ImmutableList.of(), 2, 20, 200, 0xCAFEBABEDEADBEEFL);
ShardInfo shardInfo3 = new ShardInfo(uuid3, bucketNumber, ImmutableSet.of("node3"), ImmutableList.of(), 3, 30, 300, 0xFEDCBA0987654321L);
List<ShardInfo> shards = ImmutableList.of(shardInfo1, shardInfo2, shardInfo3);
long transactionId = shardManager.beginTransaction();
shardManager.commitShards(transactionId, tableId, ImmutableList.of(new ColumnInfo(1, BIGINT), new ColumnInfo(2, DATE)), shards, Optional.empty(), 0);
Slice schema = utf8Slice(DEFAULT_TEST_ORDERS.getSchemaName());
Slice table = utf8Slice(DEFAULT_TEST_ORDERS.getTableName());
DateTime date1 = DateTime.parse("2015-01-01T00:00");
DateTime date2 = DateTime.parse("2015-01-02T00:00");
TupleDomain<Integer> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.<Integer, Domain>builder().put(0, Domain.singleValue(createVarcharType(10), schema)).put(1, Domain.create(ValueSet.ofRanges(lessThanOrEqual(createVarcharType(10), table)), true)).put(8, Domain.create(ValueSet.ofRanges(lessThanOrEqual(BIGINT, date1.getMillis()), greaterThan(BIGINT, date2.getMillis())), true)).put(9, Domain.create(ValueSet.ofRanges(lessThanOrEqual(BIGINT, date1.getMillis()), greaterThan(BIGINT, date2.getMillis())), true)).build());
List<MaterializedRow> actual;
try (RecordCursor cursor = new ShardMetadataSystemTable(dbi).cursor(null, SESSION, tupleDomain)) {
actual = getMaterializedResults(cursor, SHARD_METADATA.getColumns());
}
assertEquals(actual.size(), 3);
List<MaterializedRow> expected = ImmutableList.of(new MaterializedRow(DEFAULT_PRECISION, schema, table, utf8Slice(uuid1.toString()), null, 100L, 10L, 1L, utf8Slice("0000000000001234"), null, null, null, null), new MaterializedRow(DEFAULT_PRECISION, schema, table, utf8Slice(uuid2.toString()), null, 200L, 20L, 2L, utf8Slice("cafebabedeadbeef"), null, null, null, null), new MaterializedRow(DEFAULT_PRECISION, schema, table, utf8Slice(uuid3.toString()), null, 300L, 30L, 3L, utf8Slice("fedcba0987654321"), null, null, null, null));
assertEquals(actual, expected);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestShardMetadataRecordCursor method getMaterializedResults.
private static List<MaterializedRow> getMaterializedResults(RecordCursor cursor, List<ColumnMetadata> columns) {
List<Type> types = columns.stream().map(ColumnMetadata::getType).collect(toList());
ImmutableList.Builder<MaterializedRow> rowBuilder = ImmutableList.builder();
for (int i = 0; i < types.size(); i++) {
assertEquals(cursor.getType(i), types.get(i));
}
while (cursor.advanceNextPosition()) {
List<Object> values = new ArrayList<>();
for (int i = 0; i < columns.size(); i++) {
Type type = columns.get(i).getType();
Class<?> javaType = type.getJavaType();
if (cursor.isNull(i)) {
values.add(null);
} else if (javaType == boolean.class) {
values.add(cursor.getBoolean(i));
} else if (javaType == long.class) {
values.add(cursor.getLong(i));
} else if (javaType == double.class) {
values.add(cursor.getDouble(i));
} else if (javaType == Slice.class) {
values.add(cursor.getSlice(i));
}
}
rowBuilder.add(new MaterializedRow(DEFAULT_PRECISION, values));
}
return rowBuilder.build();
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestSqlFunctions method testShowCreateTemporaryFunction.
@Test
public void testShowCreateTemporaryFunction() {
MaterializedRow result = computeActual(createSessionWithTempFunctionFoo(), "SHOW CREATE FUNCTION foo(bigint)").getMaterializedRows().get(0);
String createFunctionFooFormatted = "CREATE TEMPORARY FUNCTION foo (\n" + " x bigint\n" + ")\n" + "RETURNS bigint\n" + "COMMENT ''\n" + "LANGUAGE SQL\n" + "NOT DETERMINISTIC\n" + "CALLED ON NULL INPUT\n" + "RETURN (x * 2)";
assertEquals(result.getField(0), createFunctionFooFormatted);
assertEquals(result.getField(1), "bigint");
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestMemorySmoke method assertQueryResult.
private void assertQueryResult(@Language("SQL") String sql, Object... expected) {
MaterializedResult rows = computeActual(sql);
assertEquals(rows.getRowCount(), expected.length);
for (int i = 0; i < expected.length; i++) {
MaterializedRow materializedRow = rows.getMaterializedRows().get(i);
int fieldCount = materializedRow.getFieldCount();
assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
Object value = materializedRow.getField(0);
assertEquals(value, expected[i]);
assertTrue(materializedRow.getFieldCount() == 1);
}
}
Aggregations