Search in sources :

Example 46 with Literal

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

the class TestSybaseConvertModifier method testTimestampToTime.

@Test
public void testTimestampToTime() throws Exception {
    Literal c = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(89, 2, 3, 7, 8, 12, 99999), Timestamp.class);
    Function func = // $NON-NLS-1$
    LANG_FACTORY.createFunction(// $NON-NLS-1$
    "convert", new Expression[] { c, // $NON-NLS-1$
    LANG_FACTORY.createLiteral("time", String.class) }, java.sql.Time.class);
    // $NON-NLS-1$
    helpGetString1(func, "cast('1970-01-01 ' + convert(varchar, CAST('1989-03-03 07:08:12.0' AS DATETIME), 8) AS datetime)");
}
Also used : Function(org.teiid.language.Function) Literal(org.teiid.language.Literal) Test(org.junit.Test)

Example 47 with Literal

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

the class TestLog10FunctionModifier method testModifier.

public void testModifier() {
    Literal arg = LANG_FACTORY.createLiteral(new Double(5.2), Double.class);
    // $NON-NLS-1$
    Function func = LANG_FACTORY.createFunction("log10", Arrays.asList(arg), Double.class);
    Log10FunctionModifier modifier = new Log10FunctionModifier(LANG_FACTORY);
    modifier.translate(func);
    // $NON-NLS-1$
    assertEquals("log", func.getName());
    assertEquals(Double.class, func.getType());
    List<Expression> outArgs = func.getParameters();
    assertEquals(2, outArgs.size());
    assertEquals(arg, outArgs.get(1));
    assertTrue(outArgs.get(1) instanceof Literal);
    Literal newArg = (Literal) outArgs.get(0);
    assertEquals(Integer.class, newArg.getType());
    assertEquals(new Integer(10), newArg.getValue());
    // $NON-NLS-1$
    assertEquals("log(10, 5.2)", SQLStringVisitor.getSQLString(func));
}
Also used : Function(org.teiid.language.Function) Log10FunctionModifier(org.teiid.translator.jdbc.oracle.Log10FunctionModifier) Expression(org.teiid.language.Expression) Literal(org.teiid.language.Literal)

Example 48 with Literal

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

the class TestMonthOrDayNameFunctionModifier method test1.

public void test1() throws Exception {
    Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 10000000), Timestamp.class);
    helpTestMod(// $NON-NLS-1$
    arg1, // $NON-NLS-1$
    "Month", // $NON-NLS-1$
    "rtrim(TO_CHAR({ts '2004-01-21 10:05:00.01'}, 'Month'))");
}
Also used : Literal(org.teiid.language.Literal)

Example 49 with Literal

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

the class TestMonthOrDayNameFunctionModifier method test3.

public void test3() throws Exception {
    Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 10, 5, 0, 10000000), Timestamp.class);
    helpTestMod(// $NON-NLS-1$
    arg1, // $NON-NLS-1$
    "Day", // $NON-NLS-1$
    "rtrim(TO_CHAR({ts '2004-01-21 10:05:00.01'}, 'Day'))");
}
Also used : Literal(org.teiid.language.Literal)

Example 50 with Literal

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

the class TestOracleTranslator method testCharType.

@Test
public void testCharType() throws Exception {
    CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
    Command command = commandBuilder.getCommand("select id from smalla where description = 'a' and ndescription in ('b', 'c')");
    for (Literal l : CollectorVisitor.collectObjects(Literal.class, command)) {
        l.setBindEligible(true);
    }
    Connection connection = Mockito.mock(Connection.class);
    PreparedStatement ps = Mockito.mock(PreparedStatement.class);
    // $NON-NLS-1$
    Mockito.stub(connection.prepareStatement("SELECT SmallishA.ID FROM SmallishA WHERE SmallishA.description = ? AND SmallishA.ndescription IN (?, ?)")).toReturn(ps);
    OracleExecutionFactory ef = new OracleExecutionFactory();
    ef.start();
    JDBCQueryExecution e = new JDBCQueryExecution(command, connection, new FakeExecutionContextImpl(), ef);
    e.execute();
    Mockito.verify(ps, Mockito.times(1)).setObject(1, "a", OracleExecutionFactory.FIXED_CHAR_TYPE);
    Mockito.verify(ps, Mockito.times(1)).setObject(2, "b", OracleExecutionFactory.FIXED_CHAR_TYPE);
}
Also used : FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) Literal(org.teiid.language.Literal) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) JDBCQueryExecution(org.teiid.translator.jdbc.JDBCQueryExecution) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

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