Search in sources :

Example 1 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class EvaluatorIterator method init.

@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    try {
        GroupSymbol gs = null;
        String query = options.get(QUERYSTRING);
        TransformationMetadata tm = createTransformationMetadata(options.get(DDL));
        this.criteria = QueryParser.getQueryParser().parseCriteria(query);
        this.elementsInExpression = ElementCollectorVisitor.getElements(this.criteria, false);
        for (ElementSymbol es : this.elementsInExpression) {
            gs = es.getGroupSymbol();
            ResolverUtil.resolveGroup(gs, tm);
        }
        ResolverVisitor.resolveLanguageObject(this.criteria, tm);
        this.evaluatorUtil = new EvaluatorUtil(gs);
    } catch (QueryParserException e) {
        throw new IOException(e);
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    } catch (QueryResolverException e) {
        throw new IOException(e);
    } catch (TeiidComponentException e) {
        throw new IOException(e);
    }
    CommandContext cc = new CommandContext();
    this.evaluator = new Evaluator(this.evaluatorUtil.getElementMap(), null, cc);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) QueryParserException(org.teiid.api.exception.query.QueryParserException) CommandContext(org.teiid.query.util.CommandContext) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) Evaluator(org.teiid.query.eval.Evaluator) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 2 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestTupleSourceCache method testNodeId.

@Test
public void testNodeId() throws Exception {
    TupleSourceCache tsc = new TupleSourceCache();
    HardcodedDataManager pdm = new HardcodedDataManager() {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            assertEquals(1, parameterObject.nodeID);
            return Mockito.mock(TupleSource.class);
        }
    };
    CommandContext context = TestProcessor.createCommandContext();
    BufferManagerImpl bufferMgr = BufferManagerFactory.createBufferManager();
    Command command = new Insert();
    RegisterRequestParameter parameterObject = new RegisterRequestParameter("z", 1, 1);
    parameterObject.info = new RegisterRequestParameter.SharedAccessInfo();
    tsc.getSharedTupleSource(context, command, "x", parameterObject, bufferMgr, pdm);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Command(org.teiid.query.sql.lang.Command) Insert(org.teiid.query.sql.lang.Insert) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) Test(org.junit.Test)

Example 3 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestPreparedPlanCache method helpPutPreparedPlans.

// ====Help methods====//
private void helpPutPreparedPlans(SessionAwareCache<PreparedPlan> cache, DQPWorkContext session, int start, int count) {
    for (int i = 0; i < count; i++) {
        Command dummy;
        try {
            dummy = QueryParser.getQueryParser().parseCommand(EXAMPLE_QUERY + (start + i));
        } catch (QueryParserException e) {
            throw new RuntimeException(e);
        }
        CacheID id = new CacheID(session, pi, dummy.toString());
        PreparedPlan pPlan = new PreparedPlan();
        cache.put(id, Determinism.SESSION_DETERMINISTIC, pPlan, null);
        pPlan.setCommand(dummy);
        pPlan.setPlan(new RelationalPlan(new ProjectNode(i)), new CommandContext());
        AnalysisRecord analysisRecord = new AnalysisRecord(true, false);
        pPlan.setAnalysisRecord(analysisRecord);
        ArrayList<Reference> refs = new ArrayList<Reference>();
        refs.add(new Reference(1));
        pPlan.setReferences(refs);
    }
}
Also used : QueryParserException(org.teiid.api.exception.query.QueryParserException) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Reference(org.teiid.query.sql.symbol.Reference) ArrayList(java.util.ArrayList) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Command(org.teiid.query.sql.lang.Command) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ProjectNode(org.teiid.query.processor.relational.ProjectNode)

Example 4 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestFunction method testCurrentDate.

// case 2458
@Test
public void testCurrentDate() throws Exception {
    Date curDate = (Date) FunctionMethods.currentDate(new CommandContext());
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(curDate);
    assertEquals(cal1.get(Calendar.HOUR_OF_DAY), 0);
    assertEquals(cal1.get(Calendar.MINUTE), 0);
    assertEquals(cal1.get(Calendar.SECOND), 0);
    assertEquals(cal1.get(Calendar.MILLISECOND), 0);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) Calendar(java.util.Calendar) Date(java.sql.Date) Test(org.junit.Test)

Example 5 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestFunction method testRand.

@Test
public void testRand() throws Exception {
    Double d = (Double) FunctionMethods.rand(new CommandContext(), new Integer(100));
    assertEquals(new Double(0.7220096548596434), d);
    FunctionMethods.rand(new CommandContext());
}
Also used : BigInteger(java.math.BigInteger) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Aggregations

CommandContext (org.teiid.query.util.CommandContext)257 Test (org.junit.Test)179 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)104 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)95 List (java.util.List)90 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)64 ArrayList (java.util.ArrayList)44 Command (org.teiid.query.sql.lang.Command)38 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)37 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)26 Options (org.teiid.query.util.Options)20 BufferManager (org.teiid.common.buffer.BufferManager)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)19 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)18 TeiidProcessingException (org.teiid.core.TeiidProcessingException)14 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)13 BlockedException (org.teiid.common.buffer.BlockedException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)11 Table (org.teiid.metadata.Table)11