Search in sources :

Example 11 with Comparison

use of org.teiid.language.Comparison in project teiid by teiid.

the class TestCompareCriteriaImpl method testGetRightExpression.

public void testGetRightExpression() throws Exception {
    Comparison impl = example(AbstractCompareCriteria.GE, 200, 100);
    assertNotNull(impl.getRightExpression());
    assertTrue(impl.getRightExpression() instanceof Literal);
    assertEquals(new Integer(100), ((Literal) impl.getRightExpression()).getValue());
}
Also used : Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal)

Example 12 with Comparison

use of org.teiid.language.Comparison in project teiid by teiid.

the class TestJoinImpl method testGetCriteria.

public void testGetCriteria() throws Exception {
    Join join = example(JoinType.JOIN_INNER);
    assertTrue(join.getCondition() instanceof Comparison);
}
Also used : Comparison(org.teiid.language.Comparison) Join(org.teiid.language.Join)

Example 13 with Comparison

use of org.teiid.language.Comparison in project teiid by teiid.

the class SubstringFunctionModifier method translate.

@Override
public List<?> translate(Function function) {
    this.modify(function);
    if (function.getParameters().size() != 3) {
        return null;
    }
    // case when length > LENGTH(string) - start + 1 then LENGTH(string) - start + 1 case when length > 0 then length end
    Expression forLength = function.getParameters().get(2);
    List<SearchedWhenClause> clauses = new ArrayList<SearchedWhenClause>(2);
    Boolean isNegative = null;
    if (forLength instanceof Literal) {
        Literal l = (Literal) forLength;
        int value = (Integer) l.getValue();
        isNegative = value < 0;
    }
    Function length = new Function(SourceSystemFunctions.LENGTH, Arrays.asList(function.getParameters().get(0)), TypeFacility.RUNTIME_TYPES.INTEGER);
    Expression from = function.getParameters().get(1);
    SearchedCase adjustedFrom = new SearchedCase(Arrays.asList(new SearchedWhenClause(new Comparison(from, length, Operator.GT), new Function(SourceSystemFunctions.ADD_OP, Arrays.asList(length, new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER))), from, TypeFacility.RUNTIME_TYPES.INTEGER);
    function.getParameters().set(1, adjustedFrom);
    Expression maxLength = new Function(SourceSystemFunctions.SUBTRACT_OP, Arrays.asList(length, new Function(SourceSystemFunctions.SUBTRACT_OP, Arrays.asList(adjustedFrom, new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER);
    clauses.add(new SearchedWhenClause(new Comparison(forLength, maxLength, Operator.GT), maxLength));
    Expression defaultExpr = null;
    if (isNegative == null) {
        clauses.add(new SearchedWhenClause(new Comparison(forLength, new Literal(0, TypeFacility.RUNTIME_TYPES.INTEGER), Operator.GT), forLength));
    } else if (isNegative) {
        // TODO: could be done in the rewriter
        return Arrays.asList(new Literal(null, TypeFacility.RUNTIME_TYPES.STRING));
    } else {
        defaultExpr = forLength;
    }
    SearchedCase sc = new SearchedCase(clauses, defaultExpr, TypeFacility.RUNTIME_TYPES.INTEGER);
    function.getParameters().set(2, sc);
    return null;
}
Also used : SearchedCase(org.teiid.language.SearchedCase) Function(org.teiid.language.Function) SearchedWhenClause(org.teiid.language.SearchedWhenClause) Expression(org.teiid.language.Expression) Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal) ArrayList(java.util.ArrayList)

Example 14 with Comparison

use of org.teiid.language.Comparison in project teiid by teiid.

the class TestDependentJoins method testBindings.

@Test
public void testBindings() throws Exception {
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.DEPENDENT_JOIN_BINDINGS, true);
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    "select pm1.g1.e1, pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, /*+ makedep */ pm2.g1 where (pm1.g1.e1 = pm2.g1.e1)", // $NON-NLS-1$
    TestOptimizer.example1(), new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm2.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0" }, new DefaultCapabilitiesFinder(caps), // $NON-NLS-1$ //$NON-NLS-2$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    List<?>[] expected = new List<?>[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "a", 1, 2 }) };
    HardcodedDataManager dataManager = new HardcodedDataManager(RealMetadataFactory.example1Cached());
    dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM g1 AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList("a", 1) });
    dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM g1 AS g_0 WHERE g_0.e1 = 'a' ORDER BY c_0", new List<?>[] { Arrays.asList("a", 2) });
    TestProcessor.helpProcess(plan, dataManager, expected);
    Select select = (Select) dataManager.getPushdownCommands().get(1);
    assertTrue(((Literal) ((Comparison) select.getWhere()).getRightExpression()).isBindEligible());
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Comparison(org.teiid.language.Comparison) Select(org.teiid.language.Select) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 15 with Comparison

use of org.teiid.language.Comparison in project teiid by teiid.

the class TestCollectorVisitor method test2.

@Test
public void test2() {
    // $NON-NLS-1$
    NamedTable g1 = new NamedTable("g1", null, null);
    // $NON-NLS-1$
    ColumnReference e1 = new ColumnReference(g1, "e1", null, String.class);
    // $NON-NLS-1$
    ColumnReference e2 = new ColumnReference(g1, "e2", null, String.class);
    Comparison cc = new Comparison(e1, e2, Operator.EQ);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    helpTestElementsUsedByGroups(cc, new String[] { "g1.e1", "g1.e2" }, new String[] { "g1" });
}
Also used : NamedTable(org.teiid.language.NamedTable) Comparison(org.teiid.language.Comparison) ColumnReference(org.teiid.language.ColumnReference) Test(org.junit.Test)

Aggregations

Comparison (org.teiid.language.Comparison)15 Literal (org.teiid.language.Literal)8 Test (org.junit.Test)5 Select (org.teiid.language.Select)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Expression (org.teiid.language.Expression)3 Function (org.teiid.language.Function)3 CommandBuilder (org.teiid.cdk.CommandBuilder)2 Array (org.teiid.language.Array)2 ColumnReference (org.teiid.language.ColumnReference)2 NamedTable (org.teiid.language.NamedTable)2 Parameter (org.teiid.language.Parameter)2 SearchedCase (org.teiid.language.SearchedCase)2 SearchedWhenClause (org.teiid.language.SearchedWhenClause)2 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)2 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)2 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1