use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestLimit method exampleMetadata.
private static TransformationMetadata exampleMetadata() {
MetadataStore metadataStore = new MetadataStore();
// Create models
// $NON-NLS-1$
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$
Schema vm1 = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
// Create physical groups
// $NON-NLS-1$
Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
// $NON-NLS-1$
Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
// $NON-NLS-1$
Table pm1g3 = RealMetadataFactory.createPhysicalGroup("g3", pm1);
// $NON-NLS-1$
Table pm1g4 = RealMetadataFactory.createPhysicalGroup("g4", pm1);
// $NON-NLS-1$
Table pm1g5 = RealMetadataFactory.createPhysicalGroup("g5", pm1);
// $NON-NLS-1$
Table pm1g6 = RealMetadataFactory.createPhysicalGroup("g6", pm1);
// Create physical elements
RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
RealMetadataFactory.createElements(pm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
RealMetadataFactory.createElements(pm1g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
List<Column> pm1g4e = RealMetadataFactory.createElements(pm1g4, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
pm1g4e.get(1).setSelectable(false);
pm1g4e.get(3).setSelectable(false);
List<Column> pm1g5e = RealMetadataFactory.createElements(pm1g5, // $NON-NLS-1$
new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
pm1g5e.get(0).setSelectable(false);
RealMetadataFactory.createElements(pm1g6, // $NON-NLS-1$ //$NON-NLS-2$
new String[] { "in", "in3" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
// Create virtual groups
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vm1g1n1 = new QueryNode("SELECT * FROM pm1.g1 LIMIT 100");
// $NON-NLS-1$
Table vm1g1 = RealMetadataFactory.createVirtualGroup("g1", vm1, vm1g1n1);
// Create virtual elements
RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vm1g2n1 = new QueryNode("SELECT * FROM vm1.g1 ORDER BY e1");
// $NON-NLS-1$
Table vm1g2 = RealMetadataFactory.createVirtualGroup("g2", vm1, vm1g2n1);
// Create virtual elements
RealMetadataFactory.createElements(vm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestFunctionPushdown method testDDLMetadata.
@Test
public void testDDLMetadata() throws Exception {
String ddl = "CREATE VIRTUAL FUNCTION SourceFunc(msg varchar) RETURNS varchar " + "OPTIONS(CATEGORY 'misc', DETERMINISM 'DETERMINISTIC', " + "\"NULL-ON-NULL\" 'true', JAVA_CLASS '" + TestFunctionPushdown.class.getName() + "', JAVA_METHOD 'sourceFunc');" + "CREATE VIEW X (Y varchar) as SELECT e1 from pm1.g1;";
MetadataFactory mf = TestDDLParser.helpParse(ddl, "model");
mf.getSchema().setPhysical(false);
MetadataStore ms = mf.asMetadataStore();
ms.merge(RealMetadataFactory.example1Cached().getMetadataStore());
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(ms, "example1");
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport("model.SourceFunc", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
helpPlan("select sourceFunc(y) from x", metadata, null, capFinder, new String[] { "SELECT sourceFunc(g_0.e1) FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
caps.setFunctionSupport("model.SourceFunc", false);
helpPlan("select sourceFunc(y) from x", metadata, null, capFinder, new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestInsertProcessing method testSelectInto_Case5412b.
@Test
public void testSelectInto_Case5412b() {
MetadataStore metadataStore = new MetadataStore();
// test setting BULK_INSERT capability to false
// $NON-NLS-1$
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$
Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.BULK_UPDATE, false);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$
new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT });
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g1 (e1, e2) VALUES (1, 1.0)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
// $NON-NLS-1$
String sql = "SELECT 1, convert(1, float) INTO pm1.g1";
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
helpProcess(plan, dataManager, expected);
Insert insert = (Insert) dataManager.getCommandHistory().iterator().next();
Constant value0 = (Constant) insert.getValues().get(0);
Constant value1 = (Constant) insert.getValues().get(1);
assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestInsertProcessing method testSelectIntoWithTypeConversion.
@Test
public void testSelectIntoWithTypeConversion() {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$
Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.BATCHED_UPDATES, true);
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new String[] { "e1", "e2", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT, DataTypeManager.DefaultDataTypes.FLOAT });
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"BatchedUpdate{I}", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
// $NON-NLS-1$
String sql = "SELECT 1, convert(1, float), convert(1, float) INTO pm1.g1";
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
helpProcess(plan, dataManager, expected);
BatchedUpdateCommand buc = (BatchedUpdateCommand) dataManager.getCommandHistory().iterator().next();
Insert insert = (Insert) buc.getUpdateCommands().get(0);
Constant value0 = (Constant) insert.getValues().get(0);
Constant value1 = (Constant) insert.getValues().get(1);
assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestInsertProcessing method testSelectInto_Case5412a.
@Test
public void testSelectInto_Case5412a() {
MetadataStore metadataStore = new MetadataStore();
// test setting BULK_INSERT capability to true
// $NON-NLS-1$
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$
Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR, true);
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$
new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT });
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g1 (e1, e2) VALUES (...)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
// $NON-NLS-1$
String sql = "SELECT 1, convert(1, float) INTO pm1.g1";
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
helpProcess(plan, dataManager, expected);
}
Aggregations