Search in sources :

Example 36 with Literal

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

the class TestOracleTranslator method testArrayComparison.

@Test
public void testArrayComparison() throws Exception {
    // $NON-NLS-1$
    String input = "select intkey from bqt1.smalla where intkey = 5";
    // $NON-NLS-1$
    String output = "SELECT g_0.IntKey FROM SmallA g_0 WHERE (g_0.IntKey, g_0.IntKey) = ((5, 2))";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    Select obj = (Select) commandBuilder.getCommand(input, true, true);
    Comparison comp = (Comparison) obj.getWhere();
    // modify to an array comparison, since there is not yet parsing support
    comp.setLeftExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getLeftExpression(), comp.getLeftExpression())));
    comp.setRightExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getRightExpression(), new Literal(2, TypeFacility.RUNTIME_TYPES.INTEGER))));
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
Also used : Array(org.teiid.language.Array) Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal) Select(org.teiid.language.Select) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 37 with Literal

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

the class TeradataSQLConversionVisitor method visit.

@Override
public void visit(In obj) {
    List<Expression> exprs = obj.getRightExpressions();
    boolean decompose = false;
    for (Expression expr : exprs) {
        if (!(expr instanceof Literal)) {
            decompose = true;
            break;
        }
    }
    if (decompose) {
        List<Expression> literals = new ArrayList<Expression>();
        Comparison.Operator opCode = obj.isNegated() ? Comparison.Operator.NE : Comparison.Operator.EQ;
        if (exprs.size() > 1) {
            Condition left = null;
            for (Expression expr : obj.getRightExpressions()) {
                if (expr instanceof Literal) {
                    literals.add(expr);
                } else {
                    if (left == null) {
                        left = LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), expr);
                    } else {
                        left = LanguageFactory.INSTANCE.createAndOr(obj.isNegated() ? Operator.AND : Operator.OR, left, LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), expr));
                    }
                }
            }
            if (!literals.isEmpty()) {
                left = LanguageFactory.INSTANCE.createAndOr(obj.isNegated() ? Operator.AND : Operator.OR, left, new In(obj.getLeftExpression(), literals, obj.isNegated()));
            }
            buffer.append(Tokens.LPAREN);
            super.visit((AndOr) left);
            buffer.append(Tokens.RPAREN);
        } else {
            super.visit(LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), exprs.get(0)));
        }
    } else {
        super.visit(obj);
    }
}
Also used : Condition(org.teiid.language.Condition) Expression(org.teiid.language.Expression) Comparison(org.teiid.language.Comparison) In(org.teiid.language.In) Literal(org.teiid.language.Literal) ArrayList(java.util.ArrayList)

Example 38 with Literal

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

the class TestEscapeSyntaxModifier method testEscape.

public void testEscape() {
    // $NON-NLS-1$
    Literal arg1 = CommandBuilder.getLanuageFactory().createLiteral("arg1", String.class);
    // $NON-NLS-1$
    Literal arg2 = CommandBuilder.getLanuageFactory().createLiteral("arg2", String.class);
    // $NON-NLS-1$
    Function func = CommandBuilder.getLanuageFactory().createFunction("concat", Arrays.asList(arg1, arg2), Integer.class);
    helpTest(func, "{fn concat('arg1', 'arg2')}");
}
Also used : Function(org.teiid.language.Function) Literal(org.teiid.language.Literal)

Example 39 with Literal

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

the class TestExtractFunctionModifier method test1.

public void test1() throws Exception {
    Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTestMod(arg1, "EXTRACT(MONTH FROM {d '2004-01-21'})", "month");
}
Also used : Literal(org.teiid.language.Literal)

Example 40 with Literal

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

the class TestExtractFunctionModifier method test3.

public void test3() throws Exception {
    Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTestMod(arg1, "EXTRACT(YEAR FROM {d '2004-01-21'})", "year");
}
Also used : Literal(org.teiid.language.Literal)

Aggregations

Literal (org.teiid.language.Literal)82 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)18 Expression (org.teiid.language.Expression)17 TranslatorException (org.teiid.translator.TranslatorException)16 Function (org.teiid.language.Function)15 Argument (org.teiid.language.Argument)12 ColumnReference (org.teiid.language.ColumnReference)10 Column (org.teiid.metadata.Column)10 Comparison (org.teiid.language.Comparison)9 ExpressionValueSource (org.teiid.language.ExpressionValueSource)7 List (java.util.List)5 Call (org.teiid.language.Call)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4 DBCollection (com.mongodb.DBCollection)3 Timestamp (java.sql.Timestamp)3 Array (org.teiid.language.Array)3 Command (org.teiid.language.Command)3 Insert (org.teiid.language.Insert)3