use of org.teiid.metadata.Schema in project teiid by teiid.
the class ParmHolder method addSchema.
/**
***************
* Methods for Adding the source metadata
****************
*/
protected Schema addSchema(String s) throws TranslatorException {
Schema sc = new Schema();
sc.setName(s);
sc.setPhysical(true);
metadataFactory.getMetadataStore().addSchema(sc);
return sc;
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestValidator method exampleMetadata4.
public static TransformationMetadata exampleMetadata4() {
MetadataStore metadataStore = new MetadataStore();
// Create metadata objects
// $NON-NLS-1$
Schema modelObj = RealMetadataFactory.createPhysicalModel("test", metadataStore);
// $NON-NLS-1$
Table groupObj = RealMetadataFactory.createPhysicalGroup("group", modelObj);
// $NON-NLS-1$
RealMetadataFactory.createElement("e0", groupObj, DataTypeManager.DefaultDataTypes.INTEGER);
// $NON-NLS-1$
RealMetadataFactory.createElement("e1", groupObj, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$
RealMetadataFactory.createElement("e2", groupObj, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$
Schema vModelObj = RealMetadataFactory.createVirtualModel("vTest", metadataStore);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vNode = new QueryNode("SELECT * FROM test.group");
// $NON-NLS-1$
Table vGroupObj = RealMetadataFactory.createVirtualGroup("vGroup", vModelObj, vNode);
// $NON-NLS-1$
Column vElemObj0 = RealMetadataFactory.createElement("e0", vGroupObj, DataTypeManager.DefaultDataTypes.INTEGER);
// $NON-NLS-1$
Column vElemObj1 = RealMetadataFactory.createElement("e1", vGroupObj, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$
RealMetadataFactory.createElement("e2", vGroupObj, DataTypeManager.DefaultDataTypes.STRING);
List<Column> elements = new ArrayList<Column>(2);
elements.add(vElemObj0);
elements.add(vElemObj1);
// e1 //$NON-NLS-1$
RealMetadataFactory.createAccessPattern("ap1", vGroupObj, elements);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vNode2 = new QueryNode("SELECT * FROM vTest.vGroup");
// $NON-NLS-1$
Table vGroupObj2 = RealMetadataFactory.createVirtualGroup("vGroup2", vModelObj, vNode2);
// $NON-NLS-1$
Column vElemObj20 = RealMetadataFactory.createElement("e0", vGroupObj2, DataTypeManager.DefaultDataTypes.INTEGER);
// $NON-NLS-1$
Column vElemObj21 = RealMetadataFactory.createElement("e1", vGroupObj2, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$
RealMetadataFactory.createElement("e2", vGroupObj2, DataTypeManager.DefaultDataTypes.STRING);
elements = new ArrayList<Column>(2);
elements.add(vElemObj20);
elements.add(vElemObj21);
// e1 //$NON-NLS-1$
RealMetadataFactory.createAccessPattern("vTest.vGroup2.ap1", vGroupObj2, elements);
return RealMetadataFactory.createTransformationMetadata(metadataStore, "example4");
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestValidator method exampleMetadata3.
public static TransformationMetadata exampleMetadata3() {
MetadataStore metadataStore = new MetadataStore();
// Create metadata objects
// $NON-NLS-1$
Schema modelObj = RealMetadataFactory.createPhysicalModel("test", metadataStore);
// $NON-NLS-1$
Table groupObj = RealMetadataFactory.createPhysicalGroup("group", modelObj);
// $NON-NLS-1$
RealMetadataFactory.createElement("e0", groupObj, DataTypeManager.DefaultDataTypes.INTEGER);
// $NON-NLS-1$
Column elemObj1 = RealMetadataFactory.createElement("e1", groupObj, DataTypeManager.DefaultDataTypes.STRING);
elemObj1.setNullType(NullType.No_Nulls);
elemObj1.setDefaultValue(Boolean.FALSE.toString());
elemObj1.setAutoIncremented(true);
// $NON-NLS-1$
elemObj1.setNameInSource("e1:SEQUENCE=MYSEQUENCE.nextVal");
return RealMetadataFactory.createTransformationMetadata(metadataStore, "example3");
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class CapabilitiesUtil method supportsScalarFunction.
public static boolean supportsScalarFunction(Object modelID, Function function, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws QueryMetadataException, TeiidComponentException {
FunctionMethod method = function.getFunctionDescriptor().getMethod();
if (metadata.isVirtualModel(modelID) || method.getPushdown() == PushDown.CANNOT_PUSHDOWN) {
return false;
}
SourceCapabilities caps = getCapabilities(modelID, metadata, capFinder);
// capabilities check is only valid for non-schema scoped functions
// technically the other functions are scoped to SYS or their function model, but that's
// not formally part of their metadata yet
Schema schema = method.getParent();
// TODO: this call should be functionDescriptor.getFullName - but legacy function models are parsed without setting the parent model as the schema
String fullName = method.getFullName();
if (schema == null || !schema.isPhysical()) {
if (!caps.supportsFunction(fullName)) {
if (SourceSystemFunctions.CONCAT2.equalsIgnoreCase(fullName)) {
// special handling for delayed rewrite of concat2
return (schema == null && caps.supportsFunction(SourceSystemFunctions.CONCAT) && caps.supportsFunction(SourceSystemFunctions.IFNULL) && caps.supportsCapability(Capability.QUERY_SEARCHED_CASE));
} else if (SourceSystemFunctions.FROM_UNIXTIME.equalsIgnoreCase(fullName)) {
return (schema == null && caps.supportsFunction(SourceSystemFunctions.TIMESTAMPADD));
} else if (SourceSystemFunctions.FROM_UNIXTIME.equalsIgnoreCase(fullName)) {
return (schema == null && caps.supportsFunction(SourceSystemFunctions.TIMESTAMPDIFF));
} else {
return false;
}
}
if (FunctionLibrary.isConvert(function)) {
Class<?> fromType = function.getArg(0).getType();
Class<?> targetType = function.getType();
if (fromType == targetType) {
// this should be removed in rewrite
return true;
}
return caps.supportsConvert(DataTypeManager.getTypeCode(fromType), DataTypeManager.getTypeCode(targetType));
}
} else if (!isSameConnector(modelID, schema, metadata, capFinder)) {
return caps.supportsFunction(fullName);
}
return true;
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class EmbeddedServer method getSchemaDdl.
/**
* Get the effective ddl text for the given schema
* @param vdbName
* @param schemaName
* @return the ddl or null if the vdb/schema does not exist
*/
public String getSchemaDdl(String vdbName, String schemaName) {
// $NON-NLS-1$
VDBMetaData vdb = repo.getVDB(vdbName, "1");
if (vdb == null) {
return null;
}
TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
if (metadata == null) {
return null;
}
Schema schema = metadata.getMetadataStore().getSchema(schemaName);
if (schema == null) {
return null;
}
return DDLStringVisitor.getDDLString(schema, null, null);
}
Aggregations