Search in sources :

Example 66 with Command

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

the class TestSqlServerConversionVisitor method testWith.

@Test
public void testWith() throws Exception {
    // $NON-NLS-1$
    String input = "with x as /*+ no_inline */ (select intkey from bqt1.smalla) select intkey from x limit 100";
    // $NON-NLS-1$
    String output = "WITH x (IntKey) AS (SELECT g_0.IntKey FROM SmallA g_0) SELECT TOP 100 g_1.intkey AS c_0 FROM x g_1";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, trans, obj);
}
Also used : Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 67 with Command

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

the class TestSqlServerConversionVisitor method testUnicodeLiteral.

@Test
public void testUnicodeLiteral() throws Exception {
    // $NON-NLS-1$
    String input = "select N'\u0FFF'";
    // $NON-NLS-1$
    String output = "SELECT N'\u0FFF'";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, trans, obj);
}
Also used : Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 68 with Command

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

the class TestSqlServerConversionVisitor method testRowLimitWithInlineViewOrderBy.

@Test
public void testRowLimitWithInlineViewOrderBy() throws Exception {
    // $NON-NLS-1$
    String input = "select intkey from (select intkey from bqt1.smalla) as x order by intkey limit 100";
    // $NON-NLS-1$
    String output = "SELECT TOP 100 v_0.c_0 FROM (SELECT g_0.IntKey AS c_0 FROM SmallA g_0) v_0 ORDER BY v_0.c_0";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, trans, obj);
}
Also used : Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 69 with Command

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

the class TestSqlServerConversionVisitor method testWithInsert.

@Test
public void testWithInsert() throws Exception {
    // $NON-NLS-1$
    String input = "insert into bqt1.smalla (intkey) with a (x) as /*+ no_inline */ (select intnum from bqt1.smallb) select x from a";
    // $NON-NLS-1$
    String output = "WITH a (x) AS (SELECT SmallB.IntNum FROM SmallB) INSERT INTO SmallA (IntKey) SELECT a.x FROM a";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, trans, obj);
}
Also used : Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 70 with Command

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

the class TestSqlServerConversionVisitor method testUniqueidentifier.

@Test
public void testUniqueidentifier() throws Exception {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema foo = RealMetadataFactory.createPhysicalModel("foo", metadataStore);
    // $NON-NLS-1$
    Table table = RealMetadataFactory.createPhysicalGroup("bar", foo);
    String[] elemNames = new String[] { // $NON-NLS-1$
    "x" };
    String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING };
    List<Column> cols = RealMetadataFactory.createElements(table, elemNames, elemTypes);
    Column obj = cols.get(0);
    // $NON-NLS-1$
    obj.setNativeType("uniqueidentifier");
    CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
    QueryMetadataInterface metadata = new TransformationMetadata(null, store, null, RealMetadataFactory.SFM.getSystemFunctions(), null);
    TranslationUtility tu = new TranslationUtility(metadata);
    // $NON-NLS-1$
    Command command = tu.parseCommand("select max(x) from bar");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("SELECT MAX(bar.x) FROM bar", trans, command);
    // $NON-NLS-1$
    command = tu.parseCommand("select * from (select max(x) as max from bar) x");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("SELECT x.max FROM (SELECT MAX(bar.x) AS max FROM bar) x", trans, command);
    // $NON-NLS-1$
    command = tu.parseCommand("insert into bar (x) values ('a')");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("INSERT INTO bar (x) VALUES ('a')", trans, command);
    trans = new SQLServerExecutionFactory();
    trans.setDatabaseVersion(SQLServerExecutionFactory.V_2000);
    trans.start();
    // $NON-NLS-1$
    command = tu.parseCommand("select max(x) from bar");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("SELECT MAX(cast(bar.x as char(36))) FROM bar", trans, command);
    // $NON-NLS-1$
    command = tu.parseCommand("select * from (select max(x) as max from bar) x");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("SELECT x.max FROM (SELECT MAX(cast(bar.x as char(36))) AS max FROM bar) x", trans, command);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) TranslationUtility(org.teiid.cdk.api.TranslationUtility) MetadataStore(org.teiid.metadata.MetadataStore) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) Column(org.teiid.metadata.Column) Command(org.teiid.language.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Aggregations

Command (org.teiid.language.Command)136 Test (org.junit.Test)99 ExecutionContext (org.teiid.translator.ExecutionContext)62 TranslationUtility (org.teiid.cdk.api.TranslationUtility)52 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)40 CommandBuilder (org.teiid.cdk.CommandBuilder)25 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)20 ResultSetExecution (org.teiid.translator.ResultSetExecution)18 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)17 UpdateExecution (org.teiid.translator.UpdateExecution)16 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 List (java.util.List)11 Connection (java.sql.Connection)10 LdapContext (javax.naming.ldap.LdapContext)9 Range (org.apache.accumulo.core.data.Range)9 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 MetadataFactory (org.teiid.metadata.MetadataFactory)8 ArrayList (java.util.ArrayList)7 FunctionTree (org.teiid.query.function.FunctionTree)7 UDFSource (org.teiid.query.function.UDFSource)7