use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class MetadataManager method getTableMetadata.
@Override
public TableMetadata getTableMetadata(Session session, TableHandle tableHandle) {
ConnectorId connectorId = tableHandle.getConnectorId();
ConnectorMetadata metadata = getMetadata(session, connectorId);
ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle());
return new TableMetadata(connectorId, tableMetadata);
}
use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class LogicalPlanner method createTableMetadata.
private ConnectorTableMetadata createTableMetadata(QualifiedObjectName table, List<ColumnMetadata> columns, Map<String, Expression> propertyExpressions, List<Expression> parameters) {
ConnectorId connectorId = metadata.getCatalogHandle(session, table.getCatalogName()).orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + table.getCatalogName()));
Map<String, Object> properties = metadata.getTablePropertyManager().getProperties(connectorId, table.getCatalogName(), propertyExpressions, session, metadata, parameters);
return new ConnectorTableMetadata(table.asSchemaTableName(), columns, properties);
}
use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class TestMemoryMetadata method testActiveTableIds.
@Test
public void testActiveTableIds() {
assertThatNoTableIsCreated();
SchemaTableName firstTableName = new SchemaTableName("default", "first_table");
metadata.createTable(SESSION, new ConnectorTableMetadata(firstTableName, ImmutableList.of(), ImmutableMap.of()));
MemoryTableHandle firstTableHandle = (MemoryTableHandle) metadata.getTableHandle(SESSION, firstTableName);
Long firstTableId = firstTableHandle.getTableId();
assertTrue(metadata.beginInsert(SESSION, firstTableHandle).getActiveTableIds().contains(firstTableId));
SchemaTableName secondTableName = new SchemaTableName("default", "second_table");
metadata.createTable(SESSION, new ConnectorTableMetadata(secondTableName, ImmutableList.of(), ImmutableMap.of()));
MemoryTableHandle secondTableHandle = (MemoryTableHandle) metadata.getTableHandle(SESSION, secondTableName);
Long secondTableId = secondTableHandle.getTableId();
assertNotEquals(firstTableId, secondTableId);
assertTrue(metadata.beginInsert(SESSION, secondTableHandle).getActiveTableIds().contains(firstTableId));
assertTrue(metadata.beginInsert(SESSION, secondTableHandle).getActiveTableIds().contains(secondTableId));
}
use of com.facebook.presto.spi.ConnectorTableMetadata 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();
}
}
use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class TestingMetadata method renameColumn.
@Override
public void renameColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle source, String target) {
ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle);
SchemaTableName tableName = getTableName(tableHandle);
ColumnMetadata columnMetadata = getColumnMetadata(session, tableHandle, source);
List<ColumnMetadata> columns = new ArrayList<>(tableMetadata.getColumns());
columns.set(columns.indexOf(columnMetadata), new ColumnMetadata(target, columnMetadata.getType(), columnMetadata.getComment(), columnMetadata.isHidden()));
tables.put(tableName, new ConnectorTableMetadata(tableName, ImmutableList.copyOf(columns), tableMetadata.getProperties()));
}
Aggregations