@Override protected Collection<? extends FunctionParameter> getChildren(final FunctionMethod parent, CommandContext cc) { ArrayList<FunctionParameter> result = new ArrayList<FunctionParameter>(parent.getInputParameters().size() + 1); result.addAll(parent.getInputParameters()); result.add(parent.getOutputParameter()); return result; }
@Override protected Collection<? extends FunctionParameter> getChildren(final FunctionMethod parent, CommandContext cc) { ArrayList<FunctionParameter> result = new ArrayList<FunctionParameter>(parent.getInputParameters().size() + 1); result.addAll(parent.getInputParameters()); result.add(parent.getOutputParameter()); return result; }
@Override protected Collection<? extends FunctionParameter> getChildren(final FunctionMethod parent, CommandContext cc) { ArrayList<FunctionParameter> result = new ArrayList<FunctionParameter>(parent.getInputParameters().size() + 1); result.addAll(parent.getInputParameters()); result.add(parent.getOutputParameter()); return result; }
private BaseColumn setCurrentExpression(Expression leftExpression) { BaseColumn old = currentExpression; if (leftExpression instanceof ColumnReference) { ColumnReference cr = (ColumnReference)leftExpression; currentExpression = cr.getMetadataObject(); } else if (leftExpression instanceof Function) { Function function = (Function)leftExpression; currentExpression = function.getMetadataObject().getOutputParameter(); } else { currentExpression = null; } //we are really looking for the native type, if it's not set then don't bother if (currentExpression != null && currentExpression.getNativeType() == null) { currentExpression = null; } return old; }
public void addFunction(FunctionMethod functionMethod) { functionMethod.setParent(this.schema); setUUID(functionMethod); for (FunctionParameter param : functionMethod.getInputParameters()) { setUUID(param); } setUUID(functionMethod.getOutputParameter()); this.schema.addFunction(functionMethod); }
@Test public void testCreateFunction() throws NoSuchMethodException, SecurityException { FunctionMethod fm = MetadataFactory.createFunctionFromMethod("x", TestMetadataFactory.class.getMethod("someFunction")); assertEquals(Boolean.class, fm.getOutputParameter().getJavaType()); fm = MetadataFactory.createFunctionFromMethod("x", TestMetadataFactory.class.getMethod("someArrayFunction")); assertEquals(String[].class, fm.getOutputParameter().getJavaType()); }
private void setFunctionMethodTypes(FunctionMethod function) { FunctionParameter outputParameter = function.getOutputParameter(); if (outputParameter != null) { setDataType(outputParameter.getRuntimeType(), outputParameter, dataTypes, outputParameter.getNullType() == NullType.Nullable); } for (FunctionParameter param : function.getInputParameters()) { setDataType(param.getRuntimeType(), param, dataTypes, param.getNullType() == NullType.Nullable); } }
private FunctionMethod addFunction(Method method, TeiidFunction f, String name) { FunctionMethod func = MetadataFactory.createFunctionFromMethod(name, method); func.setDescription(QueryPlugin.Util.getString(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_description"))); //$NON-NLS-1$ //$NON-NLS-2$ func.setCategory(f.category()); for (int i = 0; i < func.getInputParameterCount(); i++) { func.getInputParameters().get(i).setDescription(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_param" + (i+1))); //$NON-NLS-1$ //$NON-NLS-2$ } func.getOutputParameter().setDescription(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_result")); //$NON-NLS-1$ //$NON-NLS-2$ if (f.nullOnNull()) { func.setNullOnNull(true); } func.setDeterminism(f.determinism()); func.setPushdown(f.pushdown()); functions.add(func); return func; }
private FunctionMethod addFunction(Method method, TeiidFunction f, String name) { FunctionMethod func = MetadataFactory.createFunctionFromMethod(name, method); func.setDescription(QueryPlugin.Util.getString(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_description"))); //$NON-NLS-1$ //$NON-NLS-2$ func.setCategory(f.category()); for (int i = 0; i < func.getInputParameterCount(); i++) { func.getInputParameters().get(i).setDescription(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_param" + (i+1))); //$NON-NLS-1$ //$NON-NLS-2$ } func.getOutputParameter().setDescription(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_result")); //$NON-NLS-1$ //$NON-NLS-2$ if (f.nullOnNull()) { func.setNullOnNull(true); } func.setDeterminism(f.determinism()); func.setPushdown(f.pushdown()); functions.add(func); return func; }
private FunctionMethod addFunction(Method method, TeiidFunction f, String name) { FunctionMethod func = MetadataFactory.createFunctionFromMethod(name, method); func.setDescription(QueryPlugin.Util.getString(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_description"))); //$NON-NLS-1$ //$NON-NLS-2$ func.setCategory(f.category()); for (int i = 0; i < func.getInputParameterCount(); i++) { func.getInputParameters().get(i).setDescription(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_param" + (i+1))); //$NON-NLS-1$ //$NON-NLS-2$ } func.getOutputParameter().setDescription(QueryPlugin.Util.getString("SystemSource." + name.toLowerCase() + "_result")); //$NON-NLS-1$ //$NON-NLS-2$ if (f.nullOnNull()) { func.setNullOnNull(true); } func.setDeterminism(f.determinism()); func.setPushdown(f.pushdown()); functions.add(func); return func; }
@Test public void testCreateAggregateFunction() throws NoSuchMethodException, SecurityException { FunctionMethod fm = MetadataFactory.createFunctionFromMethod("x", MyUDAF.class.getMethod("addInput", String.class)); assertEquals(Boolean.class, fm.getOutputParameter().getJavaType()); assertNotNull(fm.getAggregateAttributes()); }
private void assignOids(Schema schema, TreeMap<String, RecordHolder> map) { addOid(schema, map); for (Table table : schema.getTables().values()) { addOid(table, map); addOids(table.getColumns(), map); addOids(table.getAllKeys(), map); } for (Procedure proc : schema.getProcedures().values()) { addOid(proc, map); addOids(proc.getParameters(), map); if (proc.getResultSet() != null) { addOids(proc.getResultSet().getColumns(), map); } } for (FunctionMethod func : schema.getFunctions().values()) { addOid(func, map); addOids(func.getInputParameters(), map); addOid(func.getOutputParameter(), map); } }
private void assignOids(Schema schema, TreeMap<String, RecordHolder> map) { addOid(schema, map); for (Table table : schema.getTables().values()) { addOid(table, map); addOids(table.getColumns(), map); addOids(table.getAllKeys(), map); } for (Procedure proc : schema.getProcedures().values()) { addOid(proc, map); addOids(proc.getParameters(), map); if (proc.getResultSet() != null) { addOids(proc.getResultSet().getColumns(), map); } } for (FunctionMethod func : schema.getFunctions().values()) { addOid(func, map); addOids(func.getInputParameters(), map); addOid(func.getOutputParameter(), map); } }
private void assignOids(Schema schema, TreeMap<String, RecordHolder> map) { addOid(schema, map); for (Table table : schema.getTables().values()) { addOid(table, map); addOids(table.getColumns(), map); addOids(table.getAllKeys(), map); } for (Procedure proc : schema.getProcedures().values()) { addOid(proc, map); addOids(proc.getParameters(), map); if (proc.getResultSet() != null) { addOids(proc.getResultSet().getColumns(), map); } } for (FunctionMethod func : schema.getFunctions().values()) { addOid(func, map); addOids(func.getInputParameters(), map); addOid(func.getOutputParameter(), map); } }
public void functionCreated(FunctionMethod function) { if (!assertInEditMode(Mode.SCHEMA)) { return; } assertGrant(Grant.Permission.Privilege.CREATE, Database.ResourceType.FUNCTION, function); Schema s = getCurrentSchema(); setUUID(s.getUUID(), function); for (FunctionParameter param : function.getInputParameters()) { setUUID(s.getUUID(), param); } setUUID(s.getUUID(), function.getOutputParameter()); s.addFunction(function); }
public void functionCreated(FunctionMethod function) { if (!assertInEditMode(Mode.SCHEMA)) { return; } assertGrant(Grant.Permission.Privilege.CREATE, Database.ResourceType.FUNCTION, function); Schema s = getCurrentSchema(); setUUID(s.getUUID(), function); for (FunctionParameter param : function.getInputParameters()) { setUUID(s.getUUID(), param); } setUUID(s.getUUID(), function.getOutputParameter()); s.addFunction(function); }
public void functionCreated(FunctionMethod function) { if (!assertInEditMode(Mode.SCHEMA)) { return; } assertGrant(Grant.Permission.Privilege.CREATE, Database.ResourceType.FUNCTION, function); Schema s = getCurrentSchema(); setUUID(s.getUUID(), function); for (FunctionParameter param : function.getInputParameters()) { setUUID(s.getUUID(), param); } setUUID(s.getUUID(), function.getOutputParameter()); s.addFunction(function); }
@Test public void testFunctionMetadata() throws Exception { TransformationMetadata tm = VDBMetadataFactory.getVDBMetadata(UnitTestUtil.getTestDataPath() + "/TEIIDDES992_VDB.vdb"); Map<String, FunctionMethod> functions = tm.getMetadataStore().getSchema("TEIIDDES992").getFunctions(); assertEquals(1, functions.size()); FunctionMethod fm = functions.values().iterator().next(); assertEquals("mmuuid:5c2cede9-0e18-4e4c-a531-34507abf0ff8", fm.getUUID()); assertEquals("sampleFunction", fm.getName()); assertEquals(1, fm.getInputParameters().size()); assertEquals("mmuuid:f9ded2ae-9652-414e-b5a9-74185f8703c0", fm.getOutputParameter().getUUID()); assertNotNull(fm.getInputParameters().get(0).getParent()); }
@Test public void testPushdownFunctionNoArgs() throws Exception { String ddl = "CREATE FOREIGN FUNCTION SourceFunc() RETURNS integer OPTIONS (UUID 'hello world')"; Schema s = helpParse(ddl, "model").getSchema(); FunctionMethod fm = s.getFunction("hello world"); assertNotNull(fm); assertEquals("integer", fm.getOutputParameter().getRuntimeType()); assertEquals(FunctionMethod.PushDown.MUST_PUSHDOWN, fm.getPushdown()); }
@Test public void testUDAggregate() throws Exception { String ddl = "CREATE VIRTUAL FUNCTION SourceFunc(flag boolean, msg varchar) RETURNS varchar " + "OPTIONS(CATEGORY 'misc', AGGREGATE 'true', \"allows-distinct\" 'true', UUID 'y')"; Schema s = helpParse(ddl, "model").getSchema(); FunctionMethod fm = s.getFunction("y"); assertNotNull(fm); assertEquals("string", fm.getOutputParameter().getRuntimeType()); assertEquals(FunctionMethod.PushDown.CAN_PUSHDOWN, fm.getPushdown()); assertEquals(2, fm.getInputParameterCount()); assertEquals("flag", fm.getInputParameters().get(0).getName()); assertEquals("boolean", fm.getInputParameters().get(0).getRuntimeType()); assertEquals("msg", fm.getInputParameters().get(1).getName()); assertEquals("string", fm.getInputParameters().get(1).getRuntimeType()); assertFalse( fm.getInputParameters().get(1).isVarArg()); assertNotNull(fm.getAggregateAttributes()); assertTrue(fm.getAggregateAttributes().allowsDistinct()); assertEquals(FunctionMethod.Determinism.DETERMINISTIC, fm.getDeterminism()); assertEquals("misc", fm.getCategory()); assertFalse(fm.isNullOnNull()); }