public static FunctionTree getFunctionProcedures(Schema schema) { UDFSource dummySource = new UDFSource(Collections.EMPTY_LIST); FunctionTree ft = null; for (Procedure p : schema.getProcedures().values()) { if (p.isFunction() && p.getQueryPlan() != null) { if (ft == null) { ft = new FunctionTree(schema.getName(), dummySource, false); } FunctionMethod fm = SQLParserUtil.createFunctionMethod(p); FunctionDescriptor fd = ft.addFunction(schema.getName(), dummySource, fm, false); fd.setProcedure(p); } } return ft; }
public void getConnectorMetadata(Connection conn, MetadataFactory metadataFactory) throws SQLException { super.getConnectorMetadata(conn, metadataFactory); for (String name:metadataFactory.getSchema().getTables().keySet()) { if (name.startsWith("ft_")) { Table table = metadataFactory.getSchema().getTable(name); table.setProperty(TVF, "true"); } } for (String name:metadataFactory.getSchema().getProcedures().keySet()) { Procedure proc = metadataFactory.getSchema().getProcedure(name); proc.setProperty(TVF, "true"); } } }
/** * Create a virtual model with default settings. */ public static Schema createVirtualModel(String name, MetadataStore metadataStore) { Schema schema = new Schema(); schema.setName(name); schema.setPhysical(false); metadataStore.addSchema(schema); return schema; }
@Override public void fillRow(List<Object> row, Schema model, VDBMetaData vdb, TransformationMetadata metadata, CommandContext cc, SimpleIterator<Schema> iter) { row.add(vdb.getName()); row.add(model.getName()); row.add(model.isPhysical()); row.add(model.getUUID()); row.add(model.getAnnotation()); row.add(model.getPrimaryMetamodelUri()); } });
private void setUUID(String vdbName, String vdbVersion, Schema schema) { long msb = longHash(vdbName, 0); try { //if this is just an int, we'll use the old style hash int val = Integer.parseInt(vdbVersion); msb = 31*msb + val; } catch (NumberFormatException e) { msb = 31*msb + this.currentDatabase.getVersion().hashCode(); } msb = longHash(schema.getName(), msb); schema.setUUID("tid:" + MetadataFactory.hex(msb, 12)); //$NON-NLS-1$ }
/** * To be called if the MetadataFactory is deserialized to set the canonical system * type value. * @param dt * @param builtin */ public void correctDatatypes(Map<String, Datatype> dt) { this.dataTypes = dt; for (Table t : this.schema.getTables().values()) { correctDataTypes(t.getColumns()); } for (Procedure p : this.schema.getProcedures().values()) { correctDataTypes(p.getParameters()); if (p.getResultSet() != null) { correctDataTypes(p.getResultSet().getColumns()); } } for (FunctionMethod p : this.schema.getFunctions().values()) { correctDataTypes(p.getInputParameters()); } }
@Override protected NavigableMap<String, Table> getChildren(Schema s, TransformationMetadata metadata) { return s.getTables(); } }
protected boolean isValid(Schema s, VDBMetaData vdb, List<Object> rowBuffer, Criteria condition, CommandContext commandContext) throws TeiidProcessingException, TeiidComponentException { if (s == null || !vdb.isVisible(s.getName())) { return false; } return super.isValid(s, vdb, rowBuffer, condition, commandContext); }
static Table findTable(EdmEntityType entityType, MetadataStore store) { FullQualifiedName fqn = entityType.getFullQualifiedName(); // remove the vdb name String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.')+1); Schema schema = store.getSchema(withoutVDB); return schema.getTable(entityType.getName()); }
private void getProcedures(Schema model) { Map<Character, List<AbstractMetadataRecord>> entries = schemaEntries.get(model.getName()); if (entries == null) { return; FunctionMethod function = new FunctionMethod(procedureRecord.getName(), procedureRecord.getAnnotation(), model.getName(), procedureRecord.isVirtual()?PushDown.CAN_PUSHDOWN:PushDown.MUST_PUSHDOWN, null, null, args, outputParam, false, Determinism.DETERMINISTIC); function.setUUID(procedureRecord.getUUID()); function.setPushdown(PushDown.CAN_PUSHDOWN); model.addFunction(function); continue; model.addProcedure(procedureRecord);
static FunctionMethod replaceProcedureWithFunction(MetadataFactory factory, Procedure proc) throws MetadataException { if (proc.isFunction() && proc.getQueryPlan() != null) { return null; } FunctionMethod method = createFunctionMethod(proc); //remove the old proc factory.getSchema().getResolvingOrder().remove(factory.getSchema().getResolvingOrder().size() - 1); factory.getSchema().getProcedures().remove(proc.getName()); factory.getSchema().addFunction(method); return method; }
final LinkedHashMap<String, ModelMetaData> modelMetaDatas = metadata.getModelMetaDatas(); for (ModelMetaData m:modelMetaDatas.values()) { Schema schema = new Schema(); schema.setName(m.getName()); schema.setAnnotation(m.getDescription()); schema.setVisible(m.isVisible()); schema.setPhysical(m.isSource()); schema.setProperties(m.getPropertiesMap()); metadataStore.addSchema(schema);
@Test public void testMultipleCommands() throws Exception { String ddl = "CREATE VIEW V1 AS SELECT * FROM PM1.G1; " + "CREATE PROCEDURE FOO(P1 integer) RETURNS (e1 integer, e2 varchar) AS SELECT * FROM PM1.G1;"; Schema s = helpParse(ddl, "model").getSchema(); Map<String, Table> tableMap = s.getTables(); Table table = tableMap.get("V1"); assertNotNull(table); assertEquals("SELECT * FROM PM1.G1", table.getSelectTransformation()); Map<String, Procedure> procedureMap = s.getProcedures(); Procedure p = procedureMap.get("FOO"); assertNotNull(p); assertEquals("SELECT * FROM PM1.G1;", p.getQueryPlan()); }
@Override protected NavigableMap<String, Procedure> getChildren(Schema s, TransformationMetadata metadata) { return s.getProcedures(); } }
@Test public void testSchemaProperties() { ModelMetaData mmd = new ModelMetaData(); mmd.setName("foo"); mmd.addProperty("teiid_rel:data-ttl", "1"); MetadataFactory mf = new MetadataFactory("x", 1, Collections.EMPTY_MAP, mmd); Schema s = mf.getSchema(); assertEquals("foo", s.getName()); String val = s.getProperty(DataModifiable.DATA_TTL, false); assertEquals("1", val); }
public ProcedureSQLBuilder(MetadataStore metadata, EdmOperation edmOperation, OperationParameterValueProvider parameterProvider, ArrayList<SQLParameter> params) throws TeiidProcessingException { FullQualifiedName fqn = edmOperation.getFullQualifiedName(); String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.')+1); Schema schema = metadata.getSchema(withoutVDB); this.procedure = schema.getProcedure(edmOperation.getName()); this.parameterValueProvider = parameterProvider; this.sqlParameters = params; visit(edmOperation); }
/** * Parses, but does not close, the given {@link Reader} into this {@link MetadataFactory} * @param ddl * @throws MetadataException */ public void parse(Reader ddl) throws MetadataException { this.parser.parseDDL(this, ddl); HashSet<FunctionMethod> functions = new HashSet<FunctionMethod>(); for (FunctionMethod functionMethod : getSchema().getFunctions().values()) { if (!functions.add(functionMethod)) { throw new DuplicateRecordException(DataPlugin.Event.TEIID60015, DataPlugin.Util.gs(DataPlugin.Event.TEIID60015, functionMethod.getName())); } } }
public void tableDropped(String tableName) { if (!assertInEditMode(Mode.SCHEMA)) { return; } verifyTableExists(tableName); assertGrant(Grant.Permission.Privilege.DROP, Database.ResourceType.TABLE, getCurrentSchema().getTable(tableName)); Schema s = getCurrentSchema(); s.removeTable(tableName); }