use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class TestRaptorMetadata method assertTableEqual.
private static void assertTableEqual(ConnectorTableMetadata actual, ConnectorTableMetadata expected) {
assertEquals(actual.getTable(), expected.getTable());
List<ColumnMetadata> actualColumns = actual.getColumns().stream().filter(columnMetadata -> !columnMetadata.isHidden()).collect(Collectors.toList());
List<ColumnMetadata> expectedColumns = expected.getColumns();
assertEquals(actualColumns.size(), expectedColumns.size());
for (int i = 0; i < actualColumns.size(); i++) {
ColumnMetadata actualColumn = actualColumns.get(i);
ColumnMetadata expectedColumn = expectedColumns.get(i);
assertEquals(actualColumn.getName(), expectedColumn.getName());
assertEquals(actualColumn.getType(), expectedColumn.getType());
}
assertEquals(actual.getProperties(), expected.getProperties());
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class TestRaptorMetadata method testCreateTable.
@Test
public void testCreateTable() {
assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
metadata.createTable(SESSION, getOrdersTable());
ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
assertInstanceOf(tableHandle, RaptorTableHandle.class);
assertEquals(((RaptorTableHandle) tableHandle).getTableId(), 1);
ConnectorTableMetadata table = metadata.getTableMetadata(SESSION, tableHandle);
assertTableEqual(table, getOrdersTable());
ColumnHandle columnHandle = metadata.getColumnHandles(SESSION, tableHandle).get("orderkey");
assertInstanceOf(columnHandle, RaptorColumnHandle.class);
assertEquals(((RaptorColumnHandle) columnHandle).getColumnId(), 1);
ColumnMetadata columnMetadata = metadata.getColumnMetadata(SESSION, tableHandle, columnHandle);
assertNotNull(columnMetadata);
assertEquals(columnMetadata.getName(), "orderkey");
assertEquals(columnMetadata.getType(), BIGINT);
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class H2QueryRunner method insertRows.
private static void insertRows(ConnectorTableMetadata tableMetadata, Handle handle, RecordSet data) {
List<ColumnMetadata> columns = tableMetadata.getColumns().stream().filter(columnMetadata -> !columnMetadata.isHidden()).collect(toImmutableList());
String vars = Joiner.on(',').join(nCopies(columns.size(), "?"));
String sql = format("INSERT INTO %s VALUES (%s)", tableMetadata.getTable().getTableName(), vars);
RecordCursor cursor = data.cursor();
while (true) {
// insert 1000 rows at a time
PreparedBatch batch = handle.prepareBatch(sql);
for (int row = 0; row < 1000; row++) {
if (!cursor.advanceNextPosition()) {
batch.execute();
return;
}
PreparedBatchPart part = batch.add();
for (int column = 0; column < columns.size(); column++) {
Type type = columns.get(column).getType();
if (BOOLEAN.equals(type)) {
part.bind(column, cursor.getBoolean(column));
} else if (BIGINT.equals(type)) {
part.bind(column, cursor.getLong(column));
} else if (INTEGER.equals(type)) {
part.bind(column, (int) cursor.getLong(column));
} else if (DOUBLE.equals(type)) {
part.bind(column, cursor.getDouble(column));
} else if (type instanceof VarcharType) {
part.bind(column, cursor.getSlice(column).toStringUtf8());
} else if (DATE.equals(type)) {
long millisUtc = TimeUnit.DAYS.toMillis(cursor.getLong(column));
// H2 expects dates in to be millis at midnight in the JVM timezone
long localMillis = DateTimeZone.UTC.getMillisKeepLocal(DateTimeZone.getDefault(), millisUtc);
part.bind(column, new Date(localMillis));
} else {
throw new IllegalArgumentException("Unsupported type " + type);
}
}
}
batch.execute();
}
}
Aggregations