public boolean isSystemFunction(String name) { return this.getName().equalsIgnoreCase(name) && CoreConstants.SYSTEM_MODEL.equals(this.getSchema()); }
public boolean isSystemFunction(String name) { return this.getName().equalsIgnoreCase(name) && CoreConstants.SYSTEM_MODEL.equals(this.getSchema()); }
public boolean isSystemFunction(String name) { return this.getName().equalsIgnoreCase(name) && CoreConstants.SYSTEM_MODEL.equals(this.getSchema()); }
private void helpFindFunction(String fname, Class<?>[] types, FunctionDescriptor expected) { FunctionDescriptor actual = library.findFunction(fname, types); assertEquals("Function names do not match: ", expected.getName().toLowerCase(), actual.getName().toLowerCase()); //$NON-NLS-1$ assertEquals("Arg lengths do not match: ", expected.getTypes().length, actual.getTypes().length); //$NON-NLS-1$ }
/** * Insert a conversion function at specified index. This is a convenience * method to insert a conversion into the function tree. * @param index Argument index to insert conversion function at * @param functionDescriptor Conversion function descriptor */ public void insertConversion(int index, FunctionDescriptor functionDescriptor) { // Get target type for conversion Class<?> t = functionDescriptor.getReturnType(); String typeName = DataTypeManager.getDataTypeName(t); // Pull old expression at index Expression newArg[] = new Expression[] { args[index], new Constant(typeName) }; // Replace old expression with new expression, using old as arg Function func = new Function(functionDescriptor.getName(), newArg); args[index] = func; // Set function descriptor and type of new function func.setFunctionDescriptor(functionDescriptor); func.setType(t); func.makeImplicit(); }
/** * Insert a conversion function at specified index. This is a convenience * method to insert a conversion into the function tree. * @param index Argument index to insert conversion function at * @param functionDescriptor Conversion function descriptor */ public void insertConversion(int index, FunctionDescriptor functionDescriptor) { // Get target type for conversion Class<?> t = functionDescriptor.getReturnType(); String typeName = DataTypeManager.getDataTypeName(t); // Pull old expression at index Expression newArg[] = new Expression[] { args[index], new Constant(typeName) }; // Replace old expression with new expression, using old as arg Function func = new Function(functionDescriptor.getName(), newArg); args[index] = func; // Set function descriptor and type of new function func.setFunctionDescriptor(functionDescriptor); func.setType(t); func.makeImplicit(); }
/** * Insert a conversion function at specified index. This is a convenience * method to insert a conversion into the function tree. * @param index Argument index to insert conversion function at * @param functionDescriptor Conversion function descriptor */ public void insertConversion(int index, FunctionDescriptor functionDescriptor) { // Get target type for conversion Class<?> t = functionDescriptor.getReturnType(); String typeName = DataTypeManager.getDataTypeName(t); // Pull old expression at index Expression newArg[] = new Expression[] { args[index], new Constant(typeName) }; // Replace old expression with new expression, using old as arg Function func = new Function(functionDescriptor.getName(), newArg); args[index] = func; // Set function descriptor and type of new function func.setFunctionDescriptor(functionDescriptor); func.setType(t); func.makeImplicit(); }
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName())); } catch (SQLException e) { throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName())); } catch (TeiidProcessingException e) { throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName())); } catch (SQLException e) { throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName())); } catch (TeiidProcessingException e) { throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName())); } catch (SQLException e) { throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName())); } catch (TeiidProcessingException e) { throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
fail("Expected conversion at index " + i + ", but found none."); //$NON-NLS-1$ //$NON-NLS-2$ } else { assertEquals("Expected conversion function names do not match: ", expected[i].getName(), actual[i].getName()); //$NON-NLS-1$ assertEquals("Expected conversion arg lengths do not match: ", expected[i].getTypes().length, actual[i].getTypes().length); //$NON-NLS-1$
/** * IMPORTANT: source and target must be basic runtime types * @param sourceExpression * @param sourceTypeName * @param targetTypeName * @param implicit * @param library * @return */ public static Function getConversion(Expression sourceExpression, String sourceTypeName, String targetTypeName, boolean implicit, FunctionLibrary library) { Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName); Class<?> targetType = DataTypeManager.getDataTypeClass(targetTypeName); try { setDesiredType(sourceExpression, targetType, sourceExpression); } catch (QueryResolverException e) { } FunctionDescriptor fd = library.findTypedConversionFunction(srcType, DataTypeManager.getDataTypeClass(targetTypeName)); Function conversion = new Function(fd.getName(), new Expression[] { sourceExpression, new Constant(targetTypeName) }); conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName)); conversion.setFunctionDescriptor(fd); if (implicit) { conversion.makeImplicit(); } return conversion; }
/** * IMPORTANT: source and target must be basic runtime types * @param sourceExpression * @param sourceTypeName * @param targetTypeName * @param implicit * @param library * @return */ public static Function getConversion(Expression sourceExpression, String sourceTypeName, String targetTypeName, boolean implicit, FunctionLibrary library) { Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName); Class<?> targetType = DataTypeManager.getDataTypeClass(targetTypeName); try { setDesiredType(sourceExpression, targetType, sourceExpression); } catch (QueryResolverException e) { } FunctionDescriptor fd = library.findTypedConversionFunction(srcType, DataTypeManager.getDataTypeClass(targetTypeName)); Function conversion = new Function(fd.getName(), new Expression[] { sourceExpression, new Constant(targetTypeName) }); conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName)); conversion.setFunctionDescriptor(fd); if (implicit) { conversion.makeImplicit(); } return conversion; }
AggregateFunction translate(AggregateSymbol symbol) { List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>(symbol.getArgs().length); for (Expression expression : symbol.getArgs()) { params.add(translate(expression)); } String name = symbol.getAggregateFunction().name(); if (symbol.getFunctionDescriptor() != null) { name = Symbol.getShortName(symbol.getFunctionDescriptor().getName()); } else if (symbol.getAggregateFunction() == AggregateSymbol.Type.USER_DEFINED) { name = symbol.getName(); } else if (symbol.getAggregateFunction() == Type.COUNT_BIG && !supportsCountBig) { name = Type.COUNT.name(); } AggregateFunction af = new AggregateFunction(name, symbol.isDistinct(), params, symbol.getType()); af.setCondition(translate(symbol.getCondition())); af.setOrderBy(translate(symbol.getOrderBy(), false)); if (symbol.getFunctionDescriptor() != null) { af.setMetadataObject(symbol.getFunctionDescriptor().getMethod()); } return af; }
AggregateFunction translate(AggregateSymbol symbol) { List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>(symbol.getArgs().length); for (Expression expression : symbol.getArgs()) { params.add(translate(expression)); } String name = symbol.getAggregateFunction().name(); if (symbol.getFunctionDescriptor() != null) { name = Symbol.getShortName(symbol.getFunctionDescriptor().getName()); } else if (symbol.getAggregateFunction() == AggregateSymbol.Type.USER_DEFINED) { name = symbol.getName(); } else if (symbol.getAggregateFunction() == Type.COUNT_BIG && !supportsCountBig) { name = Type.COUNT.name(); } AggregateFunction af = new AggregateFunction(name, symbol.isDistinct(), params, symbol.getType()); af.setCondition(translate(symbol.getCondition())); af.setOrderBy(translate(symbol.getOrderBy(), false)); if (symbol.getFunctionDescriptor() != null) { af.setMetadataObject(symbol.getFunctionDescriptor().getMethod()); } return af; }
/** * IMPORTANT: source and target must be basic runtime types * @param sourceExpression * @param sourceTypeName * @param targetTypeName * @param implicit * @param library * @return */ public static Function getConversion(Expression sourceExpression, String sourceTypeName, String targetTypeName, boolean implicit, FunctionLibrary library) { Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName); Class<?> targetType = DataTypeManager.getDataTypeClass(targetTypeName); try { setDesiredType(sourceExpression, targetType, sourceExpression); } catch (QueryResolverException e) { } FunctionDescriptor fd = library.findTypedConversionFunction(srcType, DataTypeManager.getDataTypeClass(targetTypeName)); Function conversion = new Function(fd.getName(), new Expression[] { sourceExpression, new Constant(targetTypeName) }); conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName)); conversion.setFunctionDescriptor(fd); if (implicit) { conversion.makeImplicit(); } return conversion; }
/** test jdbc USER method */ @Test public void testUser() { //String sql = "select intkey from SmallA where user() = 'bqt2'"; // Expected left expression FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary(); FunctionDescriptor fd = library.findFunction(FunctionLibrary.USER, new Class[] { }); Function user = new Function(fd.getName(), new Expression[] {}); user.setFunctionDescriptor(fd); // Expected criteria CompareCriteria expected = new CompareCriteria(); // Expected right expression Expression e1 = new Constant("bqt2", String.class); //$NON-NLS-1$ // Expected left expression expected.setLeftExpression(user); expected.setOperator(CompareCriteria.EQ); expected.setRightExpression(e1); // Resolve the query and check against expected objects CompareCriteria actual = (CompareCriteria) helpResolveCriteria("user()='bqt2'"); //$NON-NLS-1$ assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$ }