@Override public QueryExecution executeRawQuery(RequestContext context, String query, ZoneId timezone, Map<String, String> sessionParameters) { return executeRawQuery(context, query, timezone, sessionParameters, null); }
@Override public Type getType(TypeSignature typeSignature) { return new SignatureReferenceType(typeSignature, Object.class); }
@Override public Map<String, List<SchemaField>> getCollections(String project) { return getTables(project, this::filterTables); }
@BeforeSuite @Override public void setup() throws Exception { testingEnvironment = new TestingEnvironment(); PrestoConfig prestoConfig = testingEnvironment.getPrestoConfig(); metastore = new PrestoRakamRaptorMetastore(testingEnvironment.getPrestoMetastore(), new EventBus(), new ProjectConfig(), prestoConfig); metastore.setup(); prestoQueryExecutor = new PrestoQueryExecutor(new ProjectConfig(), prestoConfig, null, metastore); materializedViewService = new PrestoMaterializedViewService( new PrestoConfig(), prestoQueryExecutor, metastore, getDatabaseMetadataStore(), Clock.systemUTC()); eventStore = new TestingPrestoEventStore(prestoQueryExecutor, prestoConfig); super.setup(); }
@Override public void deleteProject(String project) { checkProject(project); try (Handle handle = dbi.open()) { handle.createStatement("delete from project where name = :project") .bind("project", project).execute(); } for (String collectionName : getCollectionNames(project)) { String query = format("DROP TABLE %s.\"%s\".\"%s\"", prestoConfig.getColdStorageConnector(), project, collectionName); QueryResult join = new PrestoQueryExecution(defaultSession, query, true).getResult().join(); if (join.isFailed()) { LOGGER.error("Error while deleting table %s.%s : %s", project, collectionName, join.getError().toString()); } } super.onDeleteProject(project); }
@Override public void store(Event event) { queryExecutor.executeRawStatement(String.format("INSERT INTO %s.%s.%s VALUES %s", config.getColdStorageConnector(), event.project(), event.collection(), buildValues(event.properties(), event.schema()))); }
@Override public List<SchemaField> load(ProjectCollection key) throws Exception { try (Connection conn = prestoConnectionFactory.openConnection()) { ResultSet dbColumns = conn.getMetaData().getColumns(config.getColdStorageConnector(), key.project, key.collection, null); List<SchemaField> schema = convertToSchema(dbColumns); if (schema == null) { return ImmutableList.of(); } return schema; } } });
@Override public QueryExecution executeRawStatement(RequestContext context, String query, Map<String, String> sessionProperties) { return executeRawStatement(context, query, ZoneOffset.UTC, sessionProperties, null, null, true); }
public QueryExecution executeRawStatement(RequestContext context, String query, ZoneId timezone, Map<String, String> sessionProperties, String catalog, String user, boolean update) { return internalExecuteRawQuery(context, query, createSession(catalog, timezone, sessionProperties, user), update); }
@Override public List<SchemaField> getSchema(RequestContext context, String tableName) { return metastore.getCollection(context.project, MATERIALIZED_VIEW_PREFIX + tableName); }
public PrestoQueryExecution internalExecuteRawQuery(RequestContext context, String query, ClientSession clientSession, boolean update) { return new PrestoQueryExecution(clientSession, query, update); }
@PostConstruct @Override public void setup() { setupTables(); }
private static String sqlColumnType(FieldType type) { JDBCType jdbcType = jdbcType(type); if (jdbcType != null) { switch (jdbcType) { case BOOLEAN: return "boolean"; case BIGINT: return "bigint"; case DOUBLE: return "double"; case INTEGER: return "int"; case VARBINARY: return format("varbinary(%s)", MAX_BINARY_INDEX_SIZE); } } return null; }
private boolean filterTables(String tableName, String tableColumn) { return !tableName.startsWith(MATERIALIZED_VIEW_PREFIX) && !tableColumn.startsWith("$") && !tableName.startsWith("$") && !tableColumn.equals(prestoConfig.getCheckpointColumn()); }
public static <T> void daoTransaction(IDBI dbi, Class<T> daoType, Consumer<T> callback) { runTransaction(dbi, (handle, status) -> { callback.accept(handle.attach(daoType)); return null; }); }
@Override public List<SchemaField> getOrCreateCollectionFields(String project, String collection, Set<SchemaField> fields) { ValidationUtil.checkCollectionValid(collection); return getOrCreateCollectionFields(project, collection, fields, fields.size() + 1); }
@Override public ProjectCollection getUserTable(String project, boolean isEventFilterActive) { if (isEventFilterActive) { return new ProjectCollection(prestoConfig.getUserConnector() + ".users", project); } return new ProjectCollection("users", project); } }
@BeforeSuite public void setup() throws Exception { testingEnvironment = new TestingEnvironment(); PrestoConfig prestoConfig = testingEnvironment.getPrestoConfig(); InMemoryQueryMetadataStore queryMetadataStore = new InMemoryQueryMetadataStore(); metastore = new PrestoRakamRaptorMetastore(testingEnvironment.getPrestoMetastore(), new EventBus(), new ProjectConfig(), prestoConfig); metastore.setup(); PrestoQueryExecutor queryExecutor = new PrestoQueryExecutor(new ProjectConfig(), prestoConfig, null, metastore); PrestoMaterializedViewService materializedViewService = new PrestoMaterializedViewService( new PrestoConfig(), queryExecutor, metastore, queryMetadataStore, Clock.systemUTC()); QueryExecutorService queryExecutorService = new QueryExecutorService(queryExecutor, metastore, materializedViewService, '"'); retentionQueryExecutor = new PrestoRetentionQueryExecutor(new ProjectConfig(), queryExecutorService, metastore, materializedViewService, new UserPluginConfig()); testingPrestoEventStore = new TestingPrestoEventStore(queryExecutor, prestoConfig); // TODO: Presto throws "No node available" error, find a way to avoid this ugly hack. Thread.sleep(1000); super.setup(); }
@Override public QueryExecution executeRawQuery(RequestContext context, String query, Map<String, String> sessionProperties) { return executeRawQuery(context, query, ZoneOffset.UTC, sessionProperties, null); }
@Override public Map<String, List<SchemaField>> getSchemas(String project, Predicate<String> filter) { return getTables(project, (t, c) -> filter.test(t)); }