@Override public Metadata getMetadata() { return server.getMetadata(); }
@Override public Metadata getMetadata() { return coordinator.getMetadata(); }
protected Function<Column, Type> columnTypeGetter() { return column -> { String typeName = column.getType(); Type type = prestoServer.getMetadata().getType(parseTypeSignature(typeName)); if (type == null) { throw new AssertionError("Unhandled type: " + typeName); } return type; }; } }
public StandaloneQueryRunner(Session defaultSession) throws Exception { requireNonNull(defaultSession, "defaultSession is null"); try { server = createTestingPrestoServer(); } catch (Exception e) { close(); throw e; } this.prestoClient = new TestingPrestoClient(server, defaultSession); refreshNodes(); server.getMetadata().addFunctions(AbstractTestQueries.CUSTOM_FUNCTIONS); SessionPropertyManager sessionPropertyManager = server.getMetadata().getSessionPropertyManager(); sessionPropertyManager.addSystemSessionProperties(TEST_SYSTEM_PROPERTIES); sessionPropertyManager.addConnectorSessionProperties(new ConnectorId("catalog"), TEST_CATALOG_PROPERTIES); }
public boolean tableExists(Session session, String table) { return transaction(prestoServer.getTransactionManager(), prestoServer.getAccessControl()) .readOnly() .execute(session, transactionSession -> { return MetadataUtil.tableExists(prestoServer.getMetadata(), transactionSession, table); }); }
public List<QualifiedObjectName> listTables(Session session, String catalog, String schema) { return transaction(prestoServer.getTransactionManager(), prestoServer.getAccessControl()) .readOnly() .execute(session, transactionSession -> { return prestoServer.getMetadata().listTables(transactionSession, new QualifiedTablePrefix(catalog, schema)); }); }
defaultSession = defaultSession.toSessionRepresentation().toSession(coordinator.getMetadata().getSessionPropertyManager()); this.prestoClient = closer.register(new TestingPrestoClient(coordinator, defaultSession)); server.getMetadata().addFunctions(AbstractTestQueries.CUSTOM_FUNCTIONS); server.getCatalogManager().registerCatalog(bogusTestingCatalog); SessionPropertyManager sessionPropertyManager = server.getMetadata().getSessionPropertyManager(); sessionPropertyManager.addSystemSessionProperties(TEST_SYSTEM_PROPERTIES); sessionPropertyManager.addConnectorSessionProperties(bogusTestingCatalog.getConnectorId(), TEST_CATALOG_PROPERTIES);
@Test public void testTopicExists() { QualifiedObjectName name = new QualifiedObjectName("kafka", "default", topicName); transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()) .singleStatement() .execute(SESSION, session -> { Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name); assertTrue(handle.isPresent()); }); }
@Test public void testTableExists() { QualifiedObjectName name = new QualifiedObjectName("redis", "default", tableName); transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()) .singleStatement() .execute(SESSION, session -> { Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name); assertTrue(handle.isPresent()); }); }
private TableMetadata getTableMetadata(String catalog, String schema, String tableName) { Session session = getSession(); Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata(); return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()) .readOnly() .execute(session, transactionSession -> { Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(catalog, schema, tableName)); assertTrue(tableHandle.isPresent()); return metadata.getTableMetadata(transactionSession, tableHandle.get()); }); }
private Object getHiveTableProperty(String tableName, Function<HiveTableLayoutHandle, Object> propertyGetter) { Session session = getSession(); Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata(); return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()) .readOnly() .execute(session, transactionSession -> { Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName)); assertTrue(tableHandle.isPresent()); List<TableLayoutResult> layouts = metadata.getLayouts(transactionSession, tableHandle.get(), Constraint.alwaysTrue(), Optional.empty()); TableLayout layout = getOnlyElement(layouts).getLayout(); return propertyGetter.apply((HiveTableLayoutHandle) layout.getHandle().getConnectorHandle()); }); }
private HiveInsertTableHandle getHiveInsertTableHandle(Session session, String tableName) { Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata(); return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()) .execute(session, transactionSession -> { QualifiedObjectName objectName = new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName); Optional<TableHandle> handle = metadata.getTableHandle(transactionSession, objectName); InsertTableHandle insertTableHandle = metadata.beginInsert(transactionSession, handle.get()); HiveInsertTableHandle hiveInsertTableHandle = (HiveInsertTableHandle) insertTableHandle.getConnectorHandle(); metadata.finishInsert(transactionSession, insertTableHandle, ImmutableList.of(), ImmutableList.of()); return hiveInsertTableHandle; }); }
private Consumer<Plan> assertRemoteExchangesCount(int expectedRemoteExchangesCount) { return plan -> { int actualRemoteExchangesCount = searchFrom(plan.getRoot()) .where(node -> node instanceof ExchangeNode && ((ExchangeNode) node).getScope() == ExchangeNode.Scope.REMOTE) .findAll() .size(); if (actualRemoteExchangesCount != expectedRemoteExchangesCount) { Session session = getSession(); Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata(); String formattedPlan = textLogicalPlan(plan.getRoot(), plan.getTypes(), metadata.getFunctionRegistry(), StatsAndCosts.empty(), session, 0); throw new AssertionError(format( "Expected [\n%s\n] remote exchanges but found [\n%s\n] remote exchanges. Actual plan is [\n\n%s\n]", expectedRemoteExchangesCount, actualRemoteExchangesCount, formattedPlan)); } }; }
@BeforeClass public void setUp() { TestingPrestoServer coordinator = ((DistributedQueryRunner) getQueryRunner()).getCoordinator(); tester = coordinator.getProcedureTester(); // register procedures in the bogus testing catalog ProcedureRegistry procedureRegistry = coordinator.getMetadata().getProcedureRegistry(); TestingProcedures procedures = new TestingProcedures(coordinator.getProcedureTester()); procedureRegistry.addProcedures( new ConnectorId(TESTING_CATALOG), procedures.getProcedures(PROCEDURE_SCHEMA)); session = testSessionBuilder() .setCatalog(TESTING_CATALOG) .setSchema(PROCEDURE_SCHEMA) .build(); }
public static DistributedQueryRunner createRedisQueryRunner(EmbeddedRedis embeddedRedis, String dataFormat, Iterable<TpchTable<?>> tables) throws Exception { DistributedQueryRunner queryRunner = null; try { queryRunner = new DistributedQueryRunner(createSession(), 2); queryRunner.installPlugin(new TpchPlugin()); queryRunner.createCatalog("tpch", "tpch"); embeddedRedis.start(); Map<SchemaTableName, RedisTableDescription> tableDescriptions = createTpchTableDescriptions(queryRunner.getCoordinator().getMetadata(), tables, dataFormat); installRedisPlugin(embeddedRedis, queryRunner, tableDescriptions); TestingPrestoClient prestoClient = queryRunner.getClient(); log.info("Loading data..."); long startTime = System.nanoTime(); for (TpchTable<?> table : tables) { loadTpchTable(embeddedRedis, prestoClient, table, dataFormat); } log.info("Loading complete in %s", nanosSince(startTime).toString(SECONDS)); embeddedRedis.destroyJedisPool(); return queryRunner; } catch (Throwable e) { closeAllSuppress(e, queryRunner, embeddedRedis); throw e; } }
public static DistributedQueryRunner createKafkaQueryRunner(EmbeddedKafka embeddedKafka, Iterable<TpchTable<?>> tables) throws Exception { DistributedQueryRunner queryRunner = null; try { queryRunner = new DistributedQueryRunner(createSession(), 2); queryRunner.installPlugin(new TpchPlugin()); queryRunner.createCatalog("tpch", "tpch"); embeddedKafka.start(); for (TpchTable<?> table : tables) { embeddedKafka.createTopics(kafkaTopicName(table)); } Map<SchemaTableName, KafkaTopicDescription> topicDescriptions = createTpchTopicDescriptions(queryRunner.getCoordinator().getMetadata(), tables); installKafkaPlugin(embeddedKafka, queryRunner, topicDescriptions); TestingPrestoClient prestoClient = queryRunner.getClient(); log.info("Loading data..."); long startTime = System.nanoTime(); for (TpchTable<?> table : tables) { loadTpchTopic(embeddedKafka, prestoClient, table); } log.info("Loading complete in %s", nanosSince(startTime).toString(SECONDS)); return queryRunner; } catch (Throwable e) { closeAllSuppress(e, queryRunner, embeddedKafka); throw e; } }
public static DistributedQueryRunner createElasticsearchQueryRunner(EmbeddedElasticsearchNode embeddedElasticsearchNode, Iterable<TpchTable<?>> tables) throws Exception { DistributedQueryRunner queryRunner = null; try { queryRunner = DistributedQueryRunner.builder(createSession()) .setNodeCount(NODE_COUNT) .build(); queryRunner.installPlugin(new TpchPlugin()); queryRunner.createCatalog("tpch", "tpch"); embeddedElasticsearchNode.start(); ElasticsearchTableDescriptionProvider tableDescriptions = createTableDescriptions(queryRunner.getCoordinator().getMetadata()); TestingElasticsearchConnectorFactory testFactory = new TestingElasticsearchConnectorFactory(tableDescriptions); installElasticsearchPlugin(queryRunner, testFactory); TestingPrestoClient prestoClient = queryRunner.getClient(); LOG.info("Loading data..."); long startTime = System.nanoTime(); for (TpchTable<?> table : tables) { loadTpchTopic(embeddedElasticsearchNode, prestoClient, table); } LOG.info("Loading complete in %s", nanosSince(startTime).toString(SECONDS)); return queryRunner; } catch (Exception e) { closeAllSuppress(e, queryRunner, embeddedElasticsearchNode); throw e; } }
@Override public Metadata getMetadata() { return coordinator.getMetadata(); }
@Override public Metadata getMetadata() { return server.getMetadata(); }
protected Function<Column, Type> columnTypeGetter() { return column -> { String typeName = column.getType(); Type type = prestoServer.getMetadata().getType(parseTypeSignature(typeName)); if (type == null) { throw new AssertionError("Unhandled type: " + typeName); } return type; }; } }