use of org.teiid.metadata.Procedure in project teiid by teiid.
the class TestProcedureProcessor method testFunctionInput.
/**
* defect 23975
*/
@Test
public void testFunctionInput() throws Exception {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
// $NON-NLS-1$
ProcedureParameter p1 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$ //$NON-NLS-2$
ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x = '1'; exec v1.vp2(concat(x, v1.vp1.in)); END");
// $NON-NLS-1$
Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, Arrays.asList(p1), n1);
vt1.setResultSet(rs1);
// $NON-NLS-1$
ProcedureParameter p2 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode n2 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN select v1.vp2.in; end");
// $NON-NLS-1$
Procedure vt2 = RealMetadataFactory.createVirtualProcedure("vp2", v1, Arrays.asList(p2), n2);
// $NON-NLS-1$ //$NON-NLS-2$
vt2.setResultSet(RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }));
// $NON-NLS-1$
String sql = "exec v1.vp1('1')";
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "11" }) };
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
// Construct data manager with data
// Plan query
ProcessorPlan plan = getProcedurePlan(sql, metadata);
// Run query
helpTestProcess(plan, expected, new FakeDataManager(), metadata);
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class TestResolver method testExecWithDuplicateNames.
@Test
public void testExecWithDuplicateNames() {
MetadataStore metadataStore = new MetadataStore();
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ColumnSet<Procedure> rs2 = RealMetadataFactory.createResultSet("rs2", new String[] { "in", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
// $NON-NLS-1$
ProcedureParameter rs2p2 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$
Procedure sq2 = RealMetadataFactory.createStoredProcedure("sq2", pm1, Arrays.asList(rs2p2));
sq2.setResultSet(rs2);
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "example1");
// $NON-NLS-1$ //$NON-NLS-2$
helpResolveException("select * from pm1.sq2", metadata, "TEIID30114 Cannot access procedure pm1.sq2 using table semantics since the parameter and result set column names are not all unique.");
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class ODataSchemaBuilder method buildFunction.
static void buildFunction(String schemaName, Procedure proc, ArrayList<CsdlComplexType> complexTypes, ArrayList<CsdlFunction> functions, ArrayList<CsdlFunctionImport> functionImports, CsdlSchema csdlSchema) {
CsdlFunction edmFunction = new CsdlFunction();
edmFunction.setName(proc.getName());
edmFunction.setBound(false);
ArrayList<CsdlParameter> params = new ArrayList<CsdlParameter>();
for (ProcedureParameter pp : proc.getParameters()) {
EdmPrimitiveTypeKind odataType = ODataTypeManager.odataType(pp.getRuntimeType());
if (pp.getType().equals(ProcedureParameter.Type.ReturnValue)) {
edmFunction.setReturnType(new CsdlReturnType().setType(odataType.getFullQualifiedName()).setCollection(DataTypeManager.isArrayType(pp.getRuntimeType())));
continue;
}
if (pp.getType().equals(ProcedureParameter.Type.In) || pp.getType().equals(ProcedureParameter.Type.InOut)) {
CsdlParameter parameter = buildParameter(pp, odataType);
addOperationParameterAnnotations(pp, parameter, csdlSchema);
params.add(parameter);
}
}
edmFunction.setParameters(params);
// add a complex type for return resultset.
ColumnSet<Procedure> returnColumns = proc.getResultSet();
if (returnColumns != null) {
CsdlComplexType complexType = buildComplexType(proc, returnColumns, csdlSchema);
complexTypes.add(complexType);
FullQualifiedName odataType = new FullQualifiedName(schemaName, complexType.getName());
edmFunction.setReturnType((new CsdlReturnType().setType(odataType).setCollection(true)));
}
CsdlFunctionImport functionImport = new CsdlFunctionImport();
functionImport.setName(proc.getName()).setFunction(new FullQualifiedName(schemaName, proc.getName()));
addOperationAnnotations(proc, edmFunction, csdlSchema);
functions.add(edmFunction);
functionImports.add(functionImport);
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class ODataSchemaBuilder method buildProcedures.
static void buildProcedures(org.teiid.metadata.Schema schema, CsdlSchema csdlSchema) {
// procedures
ArrayList<CsdlComplexType> complexTypes = new ArrayList<CsdlComplexType>();
ArrayList<CsdlFunction> functions = new ArrayList<CsdlFunction>();
ArrayList<CsdlFunctionImport> functionImports = new ArrayList<CsdlFunctionImport>();
ArrayList<CsdlAction> actions = new ArrayList<CsdlAction>();
ArrayList<CsdlActionImport> actionImports = new ArrayList<CsdlActionImport>();
for (Procedure proc : schema.getProcedures().values()) {
if (!allowedProcedure(proc)) {
LogManager.logDetail(LogConstants.CTX_ODATA, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16032, proc.getFullName()));
continue;
}
if (isFuntion(proc)) {
buildFunction(schema.getName(), proc, complexTypes, functions, functionImports, csdlSchema);
} else {
buildAction(schema.getName(), proc, complexTypes, actions, actionImports, csdlSchema);
}
}
csdlSchema.setComplexTypes(complexTypes);
csdlSchema.setFunctions(functions);
csdlSchema.setActions(actions);
csdlSchema.getEntityContainer().setFunctionImports(functionImports);
csdlSchema.getEntityContainer().setActionImports(actionImports);
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class ODataSchemaBuilder method buildAction.
static void buildAction(String schemaName, Procedure proc, ArrayList<CsdlComplexType> complexTypes, ArrayList<CsdlAction> actions, ArrayList<CsdlActionImport> actionImports, CsdlSchema csdlSchema) {
CsdlAction edmAction = new CsdlAction();
edmAction.setName(proc.getName());
edmAction.setBound(false);
ArrayList<CsdlParameter> params = new ArrayList<CsdlParameter>();
for (ProcedureParameter pp : proc.getParameters()) {
EdmPrimitiveTypeKind odatatype = ODataTypeManager.odataType(pp.getRuntimeType());
if (pp.getType().equals(ProcedureParameter.Type.ReturnValue)) {
edmAction.setReturnType(new CsdlReturnType().setType(odatatype.getFullQualifiedName()).setCollection(DataTypeManager.isArrayType(pp.getRuntimeType())));
continue;
}
if (pp.getType().equals(ProcedureParameter.Type.In) || pp.getType().equals(ProcedureParameter.Type.InOut)) {
CsdlParameter parameter = buildParameter(pp, odatatype);
addOperationParameterAnnotations(pp, parameter, csdlSchema);
params.add(parameter);
}
}
edmAction.setParameters(params);
// add a complex type for return resultset.
ColumnSet<Procedure> returnColumns = proc.getResultSet();
if (returnColumns != null) {
CsdlComplexType complexType = buildComplexType(proc, returnColumns, csdlSchema);
complexTypes.add(complexType);
edmAction.setReturnType((new CsdlReturnType().setType(new FullQualifiedName(schemaName, complexType.getName())).setCollection(true)));
}
CsdlActionImport actionImport = new CsdlActionImport();
actionImport.setName(proc.getName()).setAction(new FullQualifiedName(schemaName, proc.getName()));
addOperationAnnotations(proc, edmAction, csdlSchema);
actions.add(edmAction);
actionImports.add(actionImport);
}
Aggregations