private boolean isSimpleMathematicalFunction(Function function) { String funcName = function.getName(); if(funcName.equals("+") || funcName.equals("-") || funcName.equals("*") || funcName.equals("/")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ Expression[] args = function.getArgs(); if(args[0] instanceof Constant || args[1] instanceof Constant) { return true; } } // fall through - not simple mathematical return false; }
public static boolean isConvert(Function function) { Expression[] args = function.getArgs(); String funcName = function.getName(); return args.length == 2 && (funcName.equalsIgnoreCase(FunctionLibrary.CONVERT) || funcName.equalsIgnoreCase(FunctionLibrary.CAST)); }
/** * @see org.teiid.query.sql.LanguageVisitor#visit(Function) */ public void visit(Function obj) { Expression[] args = obj.getArgs(); if(args != null && args.length > 0) { for(int i=0; i<args.length; i++) { args[i] = replaceExpression(args[i]); } } }
public static boolean isConvert(Function function) { Expression[] args = function.getArgs(); String funcName = function.getName(); return args.length == 2 && (funcName.equalsIgnoreCase(FunctionLibrary.CONVERT) || funcName.equalsIgnoreCase(FunctionLibrary.CAST)); }
public static boolean isConvert(Function function) { Expression[] args = function.getArgs(); String funcName = function.getName(); return args.length == 2 && (funcName.equalsIgnoreCase(FunctionLibrary.CONVERT) || funcName.equalsIgnoreCase(FunctionLibrary.CAST)); }
private boolean isSimpleMathematicalFunction(Function function) { String funcName = function.getName(); if(funcName.equals("+") || funcName.equals("-") || funcName.equals("*") || funcName.equals("/")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ Expression[] args = function.getArgs(); if(args[0] instanceof Constant || args[1] instanceof Constant) { return true; } } // fall through - not simple mathematical return false; }
/** * @see org.teiid.query.sql.LanguageVisitor#visit(Function) */ public void visit(Function obj) { Expression[] args = obj.getArgs(); if(args != null && args.length > 0) { for(int i=0; i<args.length; i++) { args[i] = replaceExpression(args[i]); } } }
/** * Compute hash code for the object - based on name and hashcode of first arg (if there is one) * @return Hash code */ public int hashCode() { int hashCode = HashCodeUtil.hashCode(0, this.getName().toUpperCase()); Expression[] thisArgs = getArgs(); if(thisArgs != null && thisArgs.length > 0 && thisArgs[0] != null) { hashCode = HashCodeUtil.hashCode(hashCode, thisArgs[0].hashCode()); } return hashCode; }
/** * Compute hash code for the object - based on name and hashcode of first arg (if there is one) * @return Hash code */ public int hashCode() { int hashCode = HashCodeUtil.hashCode(0, this.getName().toUpperCase()); Expression[] thisArgs = getArgs(); if(thisArgs != null && thisArgs.length > 0 && thisArgs[0] != null) { hashCode = HashCodeUtil.hashCode(hashCode, thisArgs[0].hashCode()); } return hashCode; }
/** * Compute hash code for the object - based on name and hashcode of first arg (if there is one) * @return Hash code */ public int hashCode() { int hashCode = HashCodeUtil.hashCode(0, this.getName().toUpperCase()); Expression[] thisArgs = getArgs(); if(thisArgs != null && thisArgs.length > 0 && thisArgs[0] != null) { hashCode = HashCodeUtil.hashCode(hashCode, thisArgs[0].hashCode()); } return hashCode; }
private void collectNotNull(Expression leftExpr, ArrayList<ElementSymbol> notNull) { if (leftExpr instanceof ElementSymbol) { notNull.add((ElementSymbol)leftExpr); } else if (leftExpr instanceof Function) { Function f = (Function)leftExpr; if (!f.getFunctionDescriptor().isNullDependent()) { for (Expression arg : f.getArgs()) { collectNotNull(arg, notNull); } } } }
private void collectNotNull(Expression leftExpr, ArrayList<ElementSymbol> notNull) { if (leftExpr instanceof ElementSymbol) { notNull.add((ElementSymbol)leftExpr); } else if (leftExpr instanceof Function) { Function f = (Function)leftExpr; if (!f.getFunctionDescriptor().isNullDependent()) { for (Expression arg : f.getArgs()) { collectNotNull(arg, notNull); } } } }
public void visit(Function obj) { preVisitVisitor(obj); Expression[] args = obj.getArgs(); if(args != null) { for(int i=0; i<args.length; i++) { visitNode(args[i]); } } postVisitVisitor(obj); } public void visit(GroupBy obj) {
public void visit(Function obj) { preVisitVisitor(obj); Expression[] args = obj.getArgs(); if(args != null) { for(int i=0; i<args.length; i++) { visitNode(args[i]); } } postVisitVisitor(obj); } public void visit(GroupBy obj) {
public void visit(Function obj) { preVisitVisitor(obj); Expression[] args = obj.getArgs(); if(args != null) { for(int i=0; i<args.length; i++) { visitNode(args[i]); } } postVisitVisitor(obj); } public void visit(GroupBy obj) {
public Expression replaceExpression(Expression element) { if (element instanceof Function && !(element instanceof AggregateSymbol) && ((Function) element).isAggregate()) { Function f = (Function)element; AggregateSymbol as = new AggregateSymbol(f.getName(), false, f.getArgs(), null); as.setType(f.getType()); as.setFunctionDescriptor(f.getFunctionDescriptor()); return as; } return element; } };
public Expression replaceExpression(Expression element) { if (element instanceof Function && !(element instanceof AggregateSymbol) && ((Function) element).isAggregate()) { Function f = (Function)element; AggregateSymbol as = new AggregateSymbol(f.getName(), false, f.getArgs(), null); as.setType(f.getType()); as.setFunctionDescriptor(f.getFunctionDescriptor()); return as; } return element; } };
@Test public void testVarArgsFunction() throws Exception { String ddl = "create foreign function func (VARIADIC z object) returns string options (JAVA_CLASS '"+this.getClass().getName()+"', JAVA_METHOD 'vararg');\n"; TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "y"); String sql = "func(('a', 'b'))"; Function func = (Function) QueryParser.getQueryParser().parseExpression(sql); ResolverVisitor.resolveLanguageObject(func, tm); assertEquals(1, func.getArgs().length); assertEquals("2", Evaluator.evaluate(func)); }
@Test public void testLongTimestampAddLiteral1() throws Exception { org.teiid.query.sql.symbol.Function ex = (org.teiid.query.sql.symbol.Function)TestFunctionResolving.getExpression("timestampadd(sql_tsi_second, 1, now())"); ex.getArgs()[1] = new Constant(1l); Function f = (Function) TstLanguageBridgeFactory.factory.translate(ex); assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, f.getParameters().get(1).getType()); }
@Test public void testResolveConvertReference() throws Exception { Function function = new Function("convert", new Expression[] {new Reference(0), new Constant(DataTypeManager.DefaultDataTypes.BOOLEAN)}); //$NON-NLS-1$ ResolverVisitor.resolveLanguageObject(function, RealMetadataFactory.example1Cached()); assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getType()); assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getArgs()[0].getType()); }