use of io.airlift.tpch.TpchTable in project flink by apache.
the class TpchDataGenerator method generateTable.
private static void generateTable(double scale, String path) throws IOException {
File dir = new File(path + "/table");
dir.mkdir();
for (TpchTable table : TpchTable.getTables()) {
Iterable generator = table.createGenerator(scale, 1, 1);
StringBuilder builder = new StringBuilder();
generator.forEach(s -> {
String line = ((TpchEntity) s).toLine().trim();
if (line.endsWith("|")) {
line = line.substring(0, line.length() - 1);
}
builder.append(line).append('\n');
});
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path + "/table/" + table.getTableName() + ".csv")))) {
writer.write(builder.toString());
}
}
}
use of io.airlift.tpch.TpchTable in project presto by prestodb.
the class CassandraQueryRunner method createCassandraQueryRunner.
public static synchronized DistributedQueryRunner createCassandraQueryRunner() throws Exception {
EmbeddedCassandra.start();
DistributedQueryRunner queryRunner = new DistributedQueryRunner(createCassandraSession("tpch"), 4);
queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch");
queryRunner.installPlugin(new CassandraPlugin());
queryRunner.createCatalog("cassandra", "cassandra", ImmutableMap.of("cassandra.contact-points", EmbeddedCassandra.getHost(), "cassandra.native-protocol-port", Integer.toString(EmbeddedCassandra.getPort()), "cassandra.allow-drop-table", "true"));
if (!tpchLoaded) {
createKeyspace(EmbeddedCassandra.getSession(), "tpch");
List<TpchTable<?>> tables = TpchTable.getTables();
copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, createCassandraSession("tpch"), tables);
for (TpchTable table : tables) {
EmbeddedCassandra.refreshSizeEstimates("tpch", table.getTableName());
}
tpchLoaded = true;
}
return queryRunner;
}
use of io.airlift.tpch.TpchTable in project presto by prestodb.
the class HiveFileFormatBenchmark method createTpchDataSet.
private static <E extends TpchEntity> TestData createTpchDataSet(FileFormat format, TpchTable<E> tpchTable, List<TpchColumn<E>> columns) {
List<String> columnNames = columns.stream().map(TpchColumn::getColumnName).collect(toList());
List<Type> columnTypes = columns.stream().map(HiveFileFormatBenchmark::getColumnType).map(type -> format.supportsDate() || !DATE.equals(type) ? type : createUnboundedVarcharType()).collect(toList());
PageBuilder pageBuilder = new PageBuilder(columnTypes);
ImmutableList.Builder<Page> pages = ImmutableList.builder();
long dataSize = 0;
for (E row : tpchTable.createGenerator(10, 1, 1)) {
pageBuilder.declarePosition();
for (int i = 0; i < columns.size(); i++) {
TpchColumn<E> column = columns.get(i);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
switch(column.getType().getBase()) {
case IDENTIFIER:
BIGINT.writeLong(blockBuilder, column.getIdentifier(row));
break;
case INTEGER:
INTEGER.writeLong(blockBuilder, column.getInteger(row));
break;
case DATE:
if (format.supportsDate()) {
DATE.writeLong(blockBuilder, column.getDate(row));
} else {
createUnboundedVarcharType().writeString(blockBuilder, column.getString(row));
}
break;
case DOUBLE:
DOUBLE.writeDouble(blockBuilder, column.getDouble(row));
break;
case VARCHAR:
createUnboundedVarcharType().writeSlice(blockBuilder, Slices.utf8Slice(column.getString(row)));
break;
default:
throw new IllegalArgumentException("Unsupported type " + column.getType());
}
}
if (pageBuilder.isFull()) {
Page page = pageBuilder.build();
pages.add(page);
pageBuilder.reset();
dataSize += page.getSizeInBytes();
if (dataSize >= MIN_DATA_SIZE) {
break;
}
}
}
return new TestData(columnNames, columnTypes, pages.build());
}
use of io.airlift.tpch.TpchTable in project presto by prestodb.
the class ThriftTpchService method getTableMetadata.
@Override
public final PrestoThriftNullableTableMetadata getTableMetadata(PrestoThriftSchemaTableName schemaTableName) {
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
if (!SCHEMAS.contains(schemaName) || TpchTable.getTables().stream().noneMatch(table -> table.getTableName().equals(tableName))) {
return new PrestoThriftNullableTableMetadata(null);
}
TpchTable<?> tpchTable = TpchTable.getTable(schemaTableName.getTableName());
List<PrestoThriftColumnMetadata> columns = new ArrayList<>();
for (TpchColumn<? extends TpchEntity> column : tpchTable.getColumns()) {
columns.add(new PrestoThriftColumnMetadata(column.getSimplifiedColumnName(), getTypeString(column), null, false));
}
List<Set<String>> indexableKeys = getIndexableKeys(schemaName, tableName);
return new PrestoThriftNullableTableMetadata(new PrestoThriftTableMetadata(schemaTableName, columns, null, !indexableKeys.isEmpty() ? indexableKeys : null));
}
Aggregations