public static UserClientConnection mockUserClientConnection(QueryContext context){ final UserSession session = context != null ? context.getSession() : Mockito.mock(UserSession.class); return new UserClientConnection(){ @Override public void addTerminationListener(GenericFutureListener<? extends Future<? super Void>> listener) { } @Override public void removeTerminationListener(GenericFutureListener<? extends Future<? super Void>> listener) { } @Override public UserSession getSession() { return session; } @Override public void sendResult(RpcOutcomeListener<Ack> listener, QueryResult result) { listener.success(Acks.OK, null); } @Override public void sendData(RpcOutcomeListener<Ack> listener, QueryWritableBatch result) { try{ AutoCloseables.close((AutoCloseable[]) result.getBuffers()); listener.success(Acks.OK, null); }catch(Exception ex){ listener.failed(new RpcException(ex)); } } }; }
/** * To facilitate generating workunits * with the assumption that QueryContext is NOT null * it's not always going to be true, since e.g. QueryContextInfo * may change between ctor and this method * @param options * @param reader * @param rootNode * @param planningSet * @return * @throws ExecutionSetupException */ private List<PlanFragment> generateWorkUnit( OptionList options, PhysicalPlanReader reader, Fragment rootNode, PlanningSet planningSet) throws ExecutionSetupException { Preconditions.checkNotNull(queryContext); return generateWorkUnit(options, queryContext.getCurrentEndpoint(), queryContext.getQueryId(), reader, rootNode, planningSet, queryContext.getSession(), queryContext.getQueryContextInfo(), queryContext.getFunctionRegistry()); }
@Override public CreatePreparedStatementResp execute() { return PreparedStatementProvider.build(plan.getRoot().getSchema(context.getFunctionRegistry()), state, context.getQueryId(), context.getSession().getCatalogName()); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); // Boilerplate AccelerationManager accelerationManager = mock(AccelerationManager.class); AccelerationDetailsPopulator populator = mock(AccelerationDetailsPopulator.class); when(populator.computeAcceleration()).thenReturn(ByteString.EMPTY_BYTE_ARRAY); when(accelerationManager.newPopulator()).thenReturn(populator); when(context.getAccelerationManager()).thenReturn(accelerationManager); when(context.getQueryUserName()).thenReturn("myuser"); when(context.getSession()).thenReturn(UserSession.Builder.newBuilder().build()); when(context.getNonDefaultOptions()).thenReturn(new OptionList()); when(catalog.getMetadataStatsCollector()).thenReturn(new MetadataStatsCollector()); }
final Quoting quoting = Optional.ofNullable(context.getSession().getInitialQuoting()).orElse(ParserConfig.QUOTING); final List<String> storeTable = new StrTokenizer(storeTablePath, '.', quoting.string.charAt(0))
ExpansionHelper(QueryContext context) { this.context = Preconditions.checkNotNull(context, "query context required"); converter = new SqlConverter( context.getPlannerSettings(), context.getOperatorTable(), context, MaterializationDescriptorProvider.EMPTY, context.getFunctionRegistry(), context.getSession(), AbstractAttemptObserver.NOOP, context.getCatalog(), context.getSubstitutionProviderFactory(), context.getConfig(), context.getScanResult()); }
@Override public CreatePreparedStatementResp execute() throws Exception { ServerPreparedStatementState state = ServerPreparedStatementState.newBuilder().setHandle(-1).setSqlQuery(sql).build(); return PreparedStatementProvider.build(schema, state, context.getQueryId(), context.getSession().getCatalogName()); }
protected QueryContext mockQueryContext(SabotContext dbContext) throws Exception { final UserSession userSession = UserSession.Builder.newBuilder().withOptionManager(dbContext.getOptionManager()).build(); final SessionOptionManager sessionOptions = (SessionOptionManager) userSession.getOptions(); final QueryOptionManager queryOptions = new QueryOptionManager(sessionOptions); final ExecutionControls executionControls = new ExecutionControls(queryOptions, NodeEndpoint.getDefaultInstance()); final OperatorTable table = new OperatorTable(FUNCTIONS()); final LogicalPlanPersistence lp = dbContext.getLpPersistence(); final CatalogService registry = dbContext.getCatalogService(); final QueryContext context = Mockito.mock(QueryContext.class); when(context.getSession()).thenReturn(userSession); when(context.getLpPersistence()).thenReturn(lp); when(context.getCatalogService()).thenReturn(registry); when(context.getFunctionRegistry()).thenReturn(FUNCTIONS()); when(context.getSession()).thenReturn(UserSession.Builder.newBuilder().setSupportComplexTypes(true).build()); when(context.getCurrentEndpoint()).thenReturn(NodeEndpoint.getDefaultInstance()); when(context.getActiveEndpoints()).thenReturn(ImmutableList.of(NodeEndpoint.getDefaultInstance())); when(context.getPlannerSettings()).thenReturn(new PlannerSettings(dbContext.getConfig(), queryOptions, dbContext.getClusterResourceInformation())); when(context.getOptions()).thenReturn(queryOptions); when(context.getConfig()).thenReturn(DEFAULT_SABOT_CONFIG); when(context.getOperatorTable()).thenReturn(table); when(context.getAllocator()).thenReturn(allocator); when(context.getExecutionControls()).thenReturn(executionControls); when(context.getMaterializationProvider()).thenReturn(Mockito.mock(MaterializationDescriptorProvider.class)); return context; }
switch(request.getType()){ case GET_CATALOGS: return new MetadataProvider.CatalogsProvider(context.getQueryId(), context.getSession(), dbContext, request.unwrap(GetCatalogsReq.class)); return new MetadataProvider.ColumnsProvider(context.getQueryId(), context.getSession(), dbContext, request.unwrap(GetColumnsReq.class)); return new MetadataProvider.SchemasProvider(context.getQueryId(), context.getSession(), dbContext, request.unwrap(GetSchemasReq.class)); return new MetadataProvider.TablesProvider(context.getQueryId(), context.getSession(), dbContext, request.unwrap(GetTablesReq.class)); return new ServerMetaProvider.ServerMetaCommandRunner(context.getQueryId(), context.getSession(), dbContext, request.unwrap(GetServerMetaReq.class)); Preconditions.checkArgument( plan.getUsername() .equals(context.getSession() .getCredentials() .getUserName()));
injector.injectChecked(queryContext.getExecutionControls(), "run-try-beginning", ForemanException.class); observers.queryStarted(queryRequest, queryContext.getSession().getCredentials().getUserName());
if (!context.getSession().isSupportComplexTypes()) { logger.debug("Client does not support complex types, add ComplexToJson operator."); phyRelNode = ComplexToJsonPrelVisitor.addComplexToJsonPrel(phyRelNode);
reader, rootOperatorFragment, queryContext.getSession(), queryContextInformation, queryContext.getFunctionRegistry());
private SqlConverter getNewConverter(QueryContext context, SqlQuery query, AttemptObserver observerForSubstitution) { Catalog catalog = context.getCatalog(); final List<String> sqlContext = query.getContext(); if(sqlContext != null){ NamespaceKey path = new NamespaceKey(sqlContext); try { catalog = catalog.resolveCatalog(path); } catch (Exception e) { throw UserException.validationError(e) .message("Unable to resolve schema path [%s]. Failure resolving [%s] portion of path.", sqlContext, path) .build(logger); } } return new SqlConverter( context.getPlannerSettings(), context.getOperatorTable(), context, context.getMaterializationProvider(), context.getFunctionRegistry(), context.getSession(), observerForSubstitution, catalog, context.getSubstitutionProviderFactory(), context.getConfig(), context.getScanResult()); }
queryContext.getMaterializationProvider(), queryContext.getFunctionRegistry(), queryContext.getSession(), observer, queryContext.getCatalog(),
protected ElasticsearchGroupScan generate(String sql) throws Exception { AttemptObserver observer = new PassthroughQueryObserver(ExecTest.mockUserClientConnection(null)); SqlConverter converter = new SqlConverter(context.getPlannerSettings(), context.getOperatorTable(), context, context.getMaterializationProvider(), context.getFunctionRegistry(), context.getSession(), observer, context.getCatalog(), context.getSubstitutionProviderFactory(), context.getConfig(), context.getScanResult()); SqlNode node = converter.parse(sql); SqlHandlerConfig config = new SqlHandlerConfig(context, converter, observer, null); NormalHandler handler = new NormalHandler(); PhysicalPlan plan = handler.getPlan(config, sql, node); List<PhysicalOperator> operators = plan.getSortedOperators(); ElasticsearchGroupScan scan = find(operators); assertNotNull("Physical plan does not contain an elasticsearch scan for query: " + sql, scan); return scan; }
if(context.getSession().getClientInfos() != null) { profileBuilder.setClientInfo(context.getSession().getClientInfos());
context.getMaterializationProvider(), context.getFunctionRegistry(), context.getSession(), observer, context.getCatalog(), return direct.create(new SetOptionHandler(context.getSession())); return direct.create(new ShowTablesHandler(catalog)); } else if (sqlNode instanceof SqlUseSchema) { return direct.create(new UseSchemaHandler(context.getSession(), catalog)); } else if (sqlNode instanceof SqlCreateReflection) { return direct.create(new AccelCreateReflectionHandler(catalog, context.getAccelerationManager()));
queryContext.getMaterializationProvider(), queryContext.getFunctionRegistry(), queryContext.getSession(), observer, queryContext.getCatalog(),