@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()); }
@Override public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws Exception { final SqlLoadMaterialization load = SqlNodeUtil.unwrap(sqlNode, SqlLoadMaterialization.class); if(!SystemUser.SYSTEM_USERNAME.equals(context.getQueryUserName())) { throw SqlExceptionHelper.parseError("$LOAD MATERIALIZATION not supported.", sql, load.getParserPosition()).build(logger); } final ReflectionService service = Preconditions.checkNotNull(context.getAccelerationManager().unwrap(ReflectionService.class), "Couldn't unwrap ReflectionService"); final List<String> components = normalizeComponents(load.getMaterializationPath()); if (components == null) { throw SqlExceptionHelper.parseError("Invalid materialization path.", sql, load.getParserPosition()).build(logger); } final ReflectionId reflectionId = new ReflectionId(components.get(0)); final Optional<ReflectionGoal> goalOptional = service.getGoal(reflectionId); if (!goalOptional.isPresent()) { throw SqlExceptionHelper.parseError("Unknown reflection id.", sql, load.getParserPosition()).build(logger); } final ReflectionGoal goal = goalOptional.get(); final MaterializationId materializationId = new MaterializationId(components.get(1)); final Optional<Materialization> materializationOpt = service.getMaterialization(materializationId); if (!materializationOpt.isPresent()) { throw SqlExceptionHelper.parseError("Unknown materialization id.", sql, load.getParserPosition()).build(logger); } final Materialization materialization = materializationOpt.get(); // if the user already made changes to the reflection goal, let's stop right here Preconditions.checkState(Objects.equals(goal.getTag(), materialization.getReflectionGoalVersion()), "materialization no longer matches its goal"); refreshMetadata(goal, materialization); return Collections.singletonList(SimpleCommandResult.successful("Materialization metadata loaded.")); }
@Override public double plan() throws Exception { try{ final RecordingObserver recording = new RecordingObserver(); final AttemptObservers observers = AttemptObservers.of(observer, recording); observers.planStart(sql); plan = handler.getPlan(config.cloneWithNewObserver(observers), sql, sqlNode); PreparedPlan prepared = new PreparedPlan(context.getQueryId(), context.getQueryUserName(), sql, plan, recording); final Long handle = PREPARE_ID.getAndIncrement(); state = ServerPreparedStatementState.newBuilder() .setHandle(handle) .setSqlQuery(sql) .setPrepareId(context.getQueryId()) .build(); planCache.put(handle, prepared); // record a partial plan so that we can grab metadata and use it (for example during view creation of via sql). observers.planCompleted(new ExecutionPlan(plan, ImmutableList.of(), ImmutableList.of())); return 1; }catch(Exception ex){ throw SqlExceptionHelper.coerceException(logger, sql, ex, true); } }
final SqlCompactMaterialization compact = SqlNodeUtil.unwrap(sqlNode, SqlCompactMaterialization.class); if(!SystemUser.SYSTEM_USERNAME.equals(config.getContext().getQueryUserName())) { throw SqlExceptionHelper.parseError("$COMPACT REFRESH not supported.", sql, compact.getParserPosition()) .build(logger);
final SqlRefreshReflection materialize = SqlNodeUtil.unwrap(sqlNode, SqlRefreshReflection.class); if(!SystemUser.SYSTEM_USERNAME.equals(config.getContext().getQueryUserName())) { throw SqlExceptionHelper.parseError("$MATERIALIZE not supported.", sql, materialize.getParserPosition()).build(logger);
public QueryProfile getQueryProfile(String description, QueryState state, UserException ex, String cancelreason) { final QueryProfile.Builder profileBuilder = QueryProfile.newBuilder() .setQuery(description) .setUser(context.getQueryUserName()) .setId(queryId) .setState(state)