@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.")); }
public QueryManager( final QueryId queryId, final QueryContext context, final CoordToExecTunnelCreator tunnelCreator, final CompletionListener completionListener, final Pointer<QueryId> prepareId, final AttemptObservers observers, final boolean verboseProfiles, final boolean includeDatasetProfiles, final Catalog catalog) { this.queryId = queryId; this.tunnelCreator = tunnelCreator; this.completionListener = completionListener; this.context = context; this.prepareId = prepareId; this.catalog = catalog; this.nonDefaultOptions = context.getNonDefaultOptions(); resourceAllocationResultObserver = new ResourceAllocationResultObserver(); observers.add(resourceAllocationResultObserver); capturer = new PlanCaptureAttemptObserver(verboseProfiles, includeDatasetProfiles, context.getFunctionRegistry(), context.getAccelerationManager().newPopulator()); observers.add(capturer); observers.add(new TimeMarker()); }
ReflectionService service = config.getContext().getAccelerationManager().unwrap(ReflectionService.class);
ReflectionService service = config.getContext().getAccelerationManager().unwrap(ReflectionService.class);
return direct.create(new UseSchemaHandler(context.getSession(), catalog)); } else if (sqlNode instanceof SqlCreateReflection) { return direct.create(new AccelCreateReflectionHandler(catalog, context.getAccelerationManager())); } else if (sqlNode instanceof SqlAddExternalReflection) { return direct.create(new AccelAddExternalReflectionHandler(catalog, context.getAccelerationManager())); } else if (sqlNode instanceof SqlAccelToggle) { return direct.create(new AccelToggleHandler(catalog, context.getAccelerationManager())); } else if (sqlNode instanceof SqlDropReflection) { return direct.create(new AccelDropReflectionHandler(catalog, context.getAccelerationManager())); } else if (sqlNode instanceof SqlForgetTable) { return direct.create(new ForgetTableHandler(catalog, context.getNamespaceService()));