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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations