public FunctionLibrary getSystemFunctionLibrary() { return new FunctionLibrary(getSystemFunctions()); }
vdb.setVersion(1); Properties p = new Properties(); this.systemFunctionManager = new SystemFunctionManager(typeMap); QueryParser parser = new QueryParser(); systemStore = loadSchema(vdb, p, "SYS", parser).asMetadataStore(); //$NON-NLS-1$ systemStore.addDataTypes(typeMap); loadSchema(vdb, p, "SYSADMIN", parser).mergeInto(systemStore); //$NON-NLS-1$ TransformationMetadata tm = new TransformationMetadata(vdb, new CompositeMetadataStore(systemStore), null, systemFunctionManager.getSystemFunctions(), null); vdb.addAttchment(QueryMetadataInterface.class, tm); MetadataValidator validator = new MetadataValidator(this.typeMap, parser);
@Test public void testGetBuiltin() throws Exception { assertEquals(18, RealMetadataFactory.SFM.getSystemFunctionLibrary().getBuiltInAggregateFunctions(false).size()); }
public FunctionLibrary getSystemFunctionLibrary() { return new FunctionLibrary(getSystemFunctions()); }
vdb.setVersion(1); Properties p = new Properties(); this.systemFunctionManager = new SystemFunctionManager(typeMap); QueryParser parser = new QueryParser(); systemStore = loadSchema(vdb, p, "SYS", parser).asMetadataStore(); //$NON-NLS-1$ systemStore.addDataTypes(typeMap); loadSchema(vdb, p, "SYSADMIN", parser).mergeInto(systemStore); //$NON-NLS-1$ TransformationMetadata tm = new TransformationMetadata(vdb, new CompositeMetadataStore(systemStore), null, systemFunctionManager.getSystemFunctions(), null); vdb.addAttchment(QueryMetadataInterface.class, tm); MetadataValidator validator = new MetadataValidator(this.typeMap, parser);
FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class } ); //$NON-NLS-1$ func.setFunctionDescriptor(desc); func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
public FunctionLibrary getSystemFunctionLibrary() { return new FunctionLibrary(getSystemFunctions()); }
vdb.setVersion(1); Properties p = new Properties(); this.systemFunctionManager = new SystemFunctionManager(typeMap); QueryParser parser = new QueryParser(); systemStore = loadSchema(vdb, p, "SYS", parser).asMetadataStore(); //$NON-NLS-1$ systemStore.addDataTypes(typeMap); loadSchema(vdb, p, "SYSADMIN", parser).mergeInto(systemStore); //$NON-NLS-1$ TransformationMetadata tm = new TransformationMetadata(vdb, new CompositeMetadataStore(systemStore), null, systemFunctionManager.getSystemFunctions(), null); vdb.addAttchment(QueryMetadataInterface.class, tm); MetadataValidator validator = new MetadataValidator(this.typeMap, parser);
@Test public void testProjectExpression() throws Exception { ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$ es1.setType(DataTypeManager.DefaultDataClasses.STRING); List elements = new ArrayList(); elements.add(es1); Function func = new Function("concat", new Expression[] { es1, new Constant("abc")}); //$NON-NLS-1$ //$NON-NLS-2$ FunctionDescriptor fd = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("concat", new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING }); //$NON-NLS-1$ func.setFunctionDescriptor(fd); func.setType(DataTypeManager.DefaultDataClasses.STRING); ExpressionSymbol expr = new ExpressionSymbol("expr", func); //$NON-NLS-1$ List projectElements = new ArrayList(); projectElements.add(expr); List[] data = new List[] { Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$ Arrays.asList(new Object[] { "2" }) }; //$NON-NLS-1$ List[] expected = new List[] { Arrays.asList(new Object[] { "1abc" }), //$NON-NLS-1$ Arrays.asList(new Object[] { "2abc" }) }; //$NON-NLS-1$ helpTestProject(projectElements, data, elements, expected, null); }
public void addUDF(String schema, Collection<FunctionMethod> methods) { if (methods == null || methods.isEmpty()) { return; } this.functions.add(new FunctionTree(schema, new UDFSource(methods))); SystemFunctionManager sfm = SystemMetadata.getInstance().getSystemFunctionManager(); functionLibrary = new FunctionLibrary(sfm.getSystemFunctions(), this.functions.toArray(new FunctionTree[this.functions.size()])); }
@Test public void testProjectExpressionFunctionFails() throws Exception { ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$ es1.setType(DataTypeManager.DefaultDataClasses.STRING); List elements = new ArrayList(); elements.add(es1); Function func = new Function("convert", new Expression[] { es1, new Constant("integer")}); //$NON-NLS-1$ //$NON-NLS-2$ FunctionDescriptor fd = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("convert", new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING }); //$NON-NLS-1$ func.setFunctionDescriptor(fd); func.setType(DataTypeManager.DefaultDataClasses.INTEGER); ExpressionSymbol expr = new ExpressionSymbol("expr", func); //$NON-NLS-1$ List projectElements = new ArrayList(); projectElements.add(expr); List[] data = new List[] { Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$ Arrays.asList(new Object[] { "2x" }) }; //$NON-NLS-1$ String expectedMessage = "TEIID30328 UNABLE TO EVALUATE CONVERT(E1, INTEGER): TEIID30384 ERROR WHILE EVALUATING FUNCTION CONVERT"; //$NON-NLS-1$ helpTestProjectFails(projectElements, data, elements, expectedMessage); }
this.systemFunctionManager.getSystemFunctions(), cmr, this, stores); lock.lock(); try {
@Test public void testUser() throws Exception { Function func = new Function("user", new Expression[] {}); //$NON-NLS-1$ FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("user", new Class[] {} ); //$NON-NLS-1$ func.setFunctionDescriptor(desc); FakeDataManager dataMgr = new FakeDataManager(); CommandContext context = new CommandContext(new Long(1), null, null, null, 0); context.setUserName("logon"); //$NON-NLS-1$ assertEquals(context.getUserName(), new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(func, Collections.emptyList()) ); }
private void buildTransformationMetadata() { TransformationMetadata metadata = new TransformationMetadata(this.vdb, new CompositeMetadataStore(this.store), null, SFM.getSystemFunctions(), null); this.vdb.addAttchment(QueryMetadataInterface.class, metadata); this.vdb.addAttchment(TransformationMetadata.class, metadata); }
FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class } ); //$NON-NLS-1$ func.setFunctionDescriptor(desc); func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
@Test public void testVarbinary() throws Exception { FunctionMethod method = new FunctionMethod( "dummy", null, null, PushDown.CANNOT_PUSHDOWN, TestFunctionTree.class.getName(), "toString", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Arrays.asList(new FunctionParameter("in", DataTypeManager.DefaultDataTypes.VARBINARY)), //$NON-NLS-1$ new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), //$NON-NLS-1$ true, Determinism.DETERMINISTIC); FunctionTree sys = RealMetadataFactory.SFM.getSystemFunctions(); FunctionLibrary fl = new FunctionLibrary(sys, new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true)); FunctionDescriptor fd = fl.findFunction("dummy", new Class<?>[] {DataTypeManager.DefaultDataClasses.VARBINARY}); String hello = "hello"; assertEquals(hello, fd.invokeFunction(new Object[] {new BinaryType(hello.getBytes())}, null, null)); }
FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, String.class } ); //$NON-NLS-1$ func.setFunctionDescriptor(desc); func.setType(DataTypeManager.DefaultDataClasses.STRING);
public static TransformationMetadata createTransformationMetadata(CompositeMetadataStore store, String vdbName, Properties vdbProperties, FunctionTree... functionModels) { VDBMetaData vdbMetaData = new VDBMetaData(); vdbMetaData.setName(vdbName); //$NON-NLS-1$ vdbMetaData.setVersion(1); if (vdbProperties != null) { vdbMetaData.setProperties(vdbProperties); } List<FunctionTree> udfs = new ArrayList<FunctionTree>(); udfs.addAll(Arrays.asList(functionModels)); for (Schema schema : store.getSchemas().values()) { vdbMetaData.addModel(RealMetadataFactory.createModel(schema.getName(), schema.isPhysical())); if (!schema.getFunctions().isEmpty()) { udfs.add(new FunctionTree(schema.getName(), new UDFSource(schema.getFunctions().values()), true)); } if (!schema.getProcedures().isEmpty()) { FunctionTree ft = FunctionTree.getFunctionProcedures(schema); if (ft != null) { udfs.add(ft); } } } TransformationMetadata metadata = new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs); vdbMetaData.addAttchment(TransformationMetadata.class, metadata); vdbMetaData.addAttchment(QueryMetadataInterface.class, metadata); return metadata; }
public void helpTestCommandPayload(Serializable payload, String property, String expectedValue) throws Exception { Function func = new Function("commandpayload", new Expression[] {}); //$NON-NLS-1$ Class[] parameterSignature = null; if(property == null) { parameterSignature = new Class[] {}; } else { parameterSignature = new Class[] { String.class }; } FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("commandpayload", parameterSignature ); //$NON-NLS-1$ func.setFunctionDescriptor(desc); FakeDataManager dataMgr = new FakeDataManager(); CommandContext context = new CommandContext(null, "user", payload, "vdb", 1, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if(property != null) { func.setArgs(new Expression[] {new Constant(property)}); } String actual = (String) new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(func, Collections.emptyList()); assertEquals(expectedValue, actual); }
@Test public void testMultiPartName() throws Exception { FunctionMethod method = new FunctionMethod( "x.y.dummy", null, null, PushDown.CANNOT_PUSHDOWN, TestFunctionTree.class.getName(), "toString", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Arrays.asList(new FunctionParameter("in", DataTypeManager.DefaultDataTypes.VARBINARY)), //$NON-NLS-1$ new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), //$NON-NLS-1$ true, Determinism.DETERMINISTIC); FunctionTree sys = RealMetadataFactory.SFM.getSystemFunctions(); FunctionLibrary fl = new FunctionLibrary(sys, new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true)); assertNotNull(fl.findFunction("dummy", new Class<?>[] {DataTypeManager.DefaultDataClasses.VARBINARY})); assertNotNull(fl.findFunction("y.dummy", new Class<?>[] {DataTypeManager.DefaultDataClasses.VARBINARY})); }