use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class TestExcelExecution method helpExecute.
private ArrayList helpExecute(String ddl, FileConnection connection, String query, boolean format) throws Exception {
ExcelExecutionFactory translator = new ExcelExecutionFactory();
translator.setFormatStrings(format);
translator.start();
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "vdb", "excel");
TranslationUtility utility = new TranslationUtility(metadata);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
ResultSetExecution execution = translator.createResultSetExecution((QueryExpression) cmd, context, utility.createRuntimeMetadata(), connection);
try {
execution.execute();
ArrayList results = new ArrayList();
while (true) {
List<?> row = execution.next();
if (row == null) {
break;
}
results.add(row);
}
return results;
} finally {
execution.close();
}
}
use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class TestExcelMetadataProcessor method getDDL.
static String getDDL(Properties props, String filename) throws TranslatorException, ResourceException {
ExcelExecutionFactory translator = new ExcelExecutionFactory();
translator.start();
String xlsName = props.getProperty("importer.excelFileName");
MetadataFactory mf = new MetadataFactory("vdb", 1, "people", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
FileConnection connection = Mockito.mock(FileConnection.class);
if (xlsName.contains("*.")) {
Mockito.stub(connection.getFile(xlsName)).toReturn(UnitTestUtil.getTestDataFile(xlsName));
File f = Mockito.mock(File.class);
Mockito.stub(f.isDirectory()).toReturn(true);
Mockito.stub(f.listFiles()).toReturn(new File[] { UnitTestUtil.getTestDataFile(filename) });
Mockito.stub(connection.getFile(xlsName)).toReturn(f);
} else {
Mockito.stub(connection.getFile(xlsName)).toReturn(UnitTestUtil.getTestDataFile(xlsName));
}
translator.getMetadata(mf, connection);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
return ddl;
}
use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class TestSQLtoSpreadsheetQuery method dummySpreadsheetMetadata.
private QueryMetadataInterface dummySpreadsheetMetadata() throws Exception {
GoogleSpreadsheetConnection conn = Mockito.mock(GoogleSpreadsheetConnection.class);
Mockito.stub(conn.getSpreadsheetInfo()).toReturn(people);
MetadataFactory factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
GoogleMetadataProcessor processor = new GoogleMetadataProcessor();
processor.process(factory, conn);
return new TransformationMetadata(null, new CompositeMetadataStore(factory.asMetadataStore()), null, RealMetadataFactory.SFM.getSystemFunctions(), null);
}
use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class TestVisitor method queryMetadataInterface.
private static TransformationMetadata queryMetadataInterface() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("couchbase");
CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
MetadataFactory mf = new MetadataFactory("couchbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
Table customer = createTable(mf, KEYSPACE, "Customer");
mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formCustomer(), mf, customer, customer.getName(), false, new Dimension());
Table order = createTable(mf, KEYSPACE, "Oder");
mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formOder(), mf, order, order.getName(), false, new Dimension());
Table t2 = createTable(mf, "T2", "T2");
mp.scanRow("T2", "`T2`", formDataTypeJson(), mf, t2, t2.getName(), false, new Dimension());
Table t3 = createTable(mf, "T3", "T3");
mp.scanRow("T3", "`T3`", nestedJson(), mf, t3, t3.getName(), false, new Dimension());
mp.scanRow("T3", "`T3`", nestedArray(), mf, t3, t3.getName(), false, new Dimension());
mp.addProcedures(mf, null);
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (MetadataException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class DataTierManagerImpl method processSystemQuery.
/**
* @param command
* @param workItem
* @return
* @throws TeiidComponentException
* @throws TeiidProcessingException
*/
private TupleSource processSystemQuery(CommandContext context, Command command, DQPWorkContext workContext) throws TeiidComponentException, TeiidProcessingException {
String vdbName = workContext.getVdbName();
String vdbVersion = workContext.getVdbVersion();
final VDBMetaData vdb = workContext.getVDB();
TransformationMetadata indexMetadata = vdb.getAttachment(TransformationMetadata.class);
CompositeMetadataStore metadata = indexMetadata.getMetadataStore();
if (command instanceof Query) {
Query query = (Query) command;
UnaryFromClause ufc = (UnaryFromClause) query.getFrom().getClauses().get(0);
GroupSymbol group = ufc.getGroup();
if (StringUtil.startsWithIgnoreCase(group.getNonCorrelationName(), CoreConstants.SYSTEM_ADMIN_MODEL)) {
final SystemAdminTables sysTable = SystemAdminTables.valueOf(group.getNonCorrelationName().substring(CoreConstants.SYSTEM_ADMIN_MODEL.length() + 1).toUpperCase());
BaseExtractionTable<?> et = systemAdminTables.get(sysTable);
return et.processQuery(query, vdb, indexMetadata, context);
}
final SystemTables sysTable = SystemTables.valueOf(group.getNonCorrelationName().substring(CoreConstants.SYSTEM_MODEL.length() + 1).toUpperCase());
BaseExtractionTable<?> et = systemTables.get(sysTable);
return et.processQuery(query, vdb, indexMetadata, context);
}
Collection<List<?>> rows = new ArrayList<List<?>>();
StoredProcedure proc = (StoredProcedure) command;
if (StringUtil.startsWithIgnoreCase(proc.getProcedureCallableName(), CoreConstants.SYSTEM_ADMIN_MODEL)) {
final SystemAdminProcs sysProc = SystemAdminProcs.valueOf(proc.getProcedureCallableName().substring(CoreConstants.SYSTEM_ADMIN_MODEL.length() + 1).toUpperCase());
switch(sysProc) {
case LOGMSG:
case ISLOGGABLE:
String level = (String) ((Constant) proc.getParameter(2).getExpression()).getValue();
String logContext = (String) ((Constant) proc.getParameter(3).getExpression()).getValue();
Object message = null;
if (sysProc == SystemAdminProcs.LOGMSG) {
message = ((Constant) proc.getParameter(4).getExpression()).getValue();
}
int msgLevel = getLevel(level);
boolean logged = false;
if (LogManager.isMessageToBeRecorded(logContext, msgLevel)) {
if (message != null) {
LogManager.log(msgLevel, logContext, message);
}
logged = true;
}
if (proc.returnParameters()) {
rows.add(Arrays.asList(logged));
}
return new CollectionTupleSource(rows.iterator());
case SETPROPERTY:
try {
String uuid = (String) ((Constant) proc.getParameter(2).getExpression()).getValue();
String key = (String) ((Constant) proc.getParameter(3).getExpression()).getValue();
Clob value = (Clob) ((Constant) proc.getParameter(4).getExpression()).getValue();
key = MetadataFactory.resolvePropertyKey(null, key);
String strVal = null;
String result = null;
if (value != null) {
if (value.length() > MAX_VALUE_LENGTH) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30548, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30548, MAX_VALUE_LENGTH));
}
strVal = ObjectConverterUtil.convertToString(value.getCharacterStream());
}
final AbstractMetadataRecord target = getByUuid(metadata, uuid);
if (target == null) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30549, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30549, uuid));
}
AbstractMetadataRecord schema = target;
while (!(schema instanceof Schema) && schema.getParent() != null) {
schema = schema.getParent();
}
if (schema instanceof Schema && vdb.getImportedModels().contains(((Schema) schema).getName())) {
// $NON-NLS-1$
throw new TeiidProcessingException(QueryPlugin.Event.TEIID31098, QueryPlugin.Util.getString("ValidationVisitor.invalid_alter", uuid));
}
if (getMetadataRepository(target, vdb) != null) {
getMetadataRepository(target, vdb).setProperty(vdbName, vdbVersion, target, key, strVal);
}
result = DdlPlan.setProperty(vdb, target, key, strVal);
if (eventDistributor != null) {
eventDistributor.setProperty(vdbName, vdbVersion, uuid, key, strVal);
}
// materialization depends upon the property values
// $NON-NLS-1$
indexMetadata.addToMetadataCache(target, "transformation/matview", null);
if (proc.returnParameters()) {
if (result == null) {
rows.add(Arrays.asList((Clob) null));
} else {
rows.add(Arrays.asList(new ClobType(new ClobImpl(result))));
}
}
return new CollectionTupleSource(rows.iterator());
} catch (SQLException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30550, e);
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30551, e);
}
}
final Table table = indexMetadata.getGroupID((String) ((Constant) proc.getParameter(1).getExpression()).getValue());
switch(sysProc) {
case SETCOLUMNSTATS:
final String columnName = (String) ((Constant) proc.getParameter(2).getExpression()).getValue();
Column c = null;
for (Column col : table.getColumns()) {
if (col.getName().equalsIgnoreCase(columnName)) {
c = col;
break;
}
}
if (c == null) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30552, columnName + TransformationMetadata.NOT_EXISTS_MESSAGE);
}
Number distinctVals = (Number) ((Constant) proc.getParameter(3).getExpression()).getValue();
Number nullVals = (Number) ((Constant) proc.getParameter(4).getExpression()).getValue();
String max = (String) ((Constant) proc.getParameter(5).getExpression()).getValue();
String min = (String) ((Constant) proc.getParameter(6).getExpression()).getValue();
final ColumnStats columnStats = new ColumnStats();
columnStats.setDistinctValues(distinctVals);
columnStats.setNullValues(nullVals);
columnStats.setMaximumValue(max);
columnStats.setMinimumValue(min);
if (getMetadataRepository(table, vdb) != null) {
getMetadataRepository(table, vdb).setColumnStats(vdbName, vdbVersion, c, columnStats);
}
DdlPlan.setColumnStats(vdb, c, columnStats);
if (eventDistributor != null) {
eventDistributor.setColumnStats(vdbName, vdbVersion, table.getParent().getName(), table.getName(), columnName, columnStats);
}
break;
case SETTABLESTATS:
Constant val = (Constant) proc.getParameter(2).getExpression();
final Number cardinality = (Number) val.getValue();
TableStats tableStats = new TableStats();
tableStats.setCardinality(cardinality);
if (getMetadataRepository(table, vdb) != null) {
getMetadataRepository(table, vdb).setTableStats(vdbName, vdbVersion, table, tableStats);
}
DdlPlan.setTableStats(vdb, table, tableStats);
if (eventDistributor != null) {
eventDistributor.setTableStats(vdbName, vdbVersion, table.getParent().getName(), table.getName(), tableStats);
}
break;
}
return new CollectionTupleSource(rows.iterator());
}
final SystemProcs sysTable = SystemProcs.valueOf(proc.getProcedureCallableName().substring(CoreConstants.SYSTEM_MODEL.length() + 1).toUpperCase());
switch(sysTable) {
case GETXMLSCHEMAS:
try {
Object groupID = indexMetadata.getGroupID((String) ((Constant) proc.getParameter(1).getExpression()).getValue());
List<SQLXMLImpl> schemas = indexMetadata.getXMLSchemas(groupID);
for (SQLXMLImpl schema : schemas) {
rows.add(Arrays.asList(new XMLType(schema)));
}
} catch (QueryMetadataException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30553, e);
}
break;
case ARRAYITERATE:
Object array = ((Constant) proc.getParameter(1).getExpression()).getValue();
if (array != null) {
final Object[] vals;
if (array instanceof Object[]) {
vals = (Object[]) array;
} else {
ArrayImpl arrayImpl = (ArrayImpl) array;
vals = arrayImpl.getValues();
}
return new CollectionTupleSource(new Iterator<List<?>>() {
int index = 0;
@Override
public boolean hasNext() {
return index < vals.length;
}
@Override
public List<?> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return Arrays.asList(vals[index++]);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
});
}
}
return new CollectionTupleSource(rows.iterator());
}
Aggregations