private Function helpResolveFunction(String sql) throws QueryParserException, QueryResolverException, TeiidComponentException { Function func = (Function)getExpression(sql); assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getType()); return func; }
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; } };
/** * e1 is of type string, so 1 should be converted to string * @throws Exception */ @Test public void testNumericConversion() throws Exception { String sql = "1.0/2"; //$NON-NLS-1$ Function f = (Function)getExpression(sql); assertEquals(DataTypeManager.DefaultDataClasses.BIG_DECIMAL, f.getType()); }
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; } };
/** * Utility to set the type of an expression if it is a Reference and has a null type. * @param expression the expression to test * @param targetType the target type, if the expression's type is null. * @throws QueryResolverException if unable to set the reference type to the target type. */ public static void setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException { if (expression instanceof Reference) { Reference ref = (Reference)expression; if (ref.isPositional() && ref.getType() == null) { if (targetType == null) { throw new QueryResolverException(QueryPlugin.Event.TEIID30083, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30083, surroundingExpression)); } ref.setType(targetType); } } else if (expression instanceof Function) { Function f = (Function)expression; if (f.getType() == null) { f.setType(targetType); } } }
/** * Utility to set the type of an expression if it is a Reference and has a null type. * @param expression the expression to test * @param targetType the target type, if the expression's type is null. * @throws QueryResolverException if unable to set the reference type to the target type. */ public static void setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException { if (expression instanceof Reference) { Reference ref = (Reference)expression; if (ref.isPositional() && ref.getType() == null) { if (targetType == null) { throw new QueryResolverException(QueryPlugin.Event.TEIID30083, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30083, surroundingExpression)); } ref.setType(targetType); } } else if (expression instanceof Function) { Function f = (Function)expression; if (f.getType() == null) { f.setType(targetType); } } }
/** * Utility to set the type of an expression if it is a Reference and has a null type. * @param expression the expression to test * @param targetType the target type, if the expression's type is null. * @throws QueryResolverException if unable to set the reference type to the target type. */ public static void setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException { if (expression instanceof Reference) { Reference ref = (Reference)expression; if (ref.isPositional() && ref.getType() == null) { if (targetType == null) { throw new QueryResolverException(QueryPlugin.Event.TEIID30083, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30083, surroundingExpression)); } ref.setType(targetType); } } else if (expression instanceof Function) { Function f = (Function)expression; if (f.getType() == null) { f.setType(targetType); } } }
/** * Return a deep copy of this object. * @return Deep copy of the object */ public Object clone() { Expression[] copyArgs = LanguageObject.Util.deepClone(this.args); Function copy = new Function(getName(), copyArgs); copy.setType(getType()); copy.setFunctionDescriptor(getFunctionDescriptor()); if(this.isImplicit()) { copy.makeImplicit(); } copy.eval = this.eval; return copy; }
/** * Return a deep copy of this object. * @return Deep copy of the object */ public Object clone() { Expression[] copyArgs = LanguageObject.Util.deepClone(this.args); Function copy = new Function(getName(), copyArgs); copy.setType(getType()); copy.setFunctionDescriptor(getFunctionDescriptor()); if(this.isImplicit()) { copy.makeImplicit(); } copy.eval = this.eval; return copy; }
/** * Return a deep copy of this object. * @return Deep copy of the object */ public Object clone() { Expression[] copyArgs = LanguageObject.Util.deepClone(this.args); Function copy = new Function(getName(), copyArgs); copy.setType(getType()); copy.setFunctionDescriptor(getFunctionDescriptor()); if(this.isImplicit()) { copy.makeImplicit(); } copy.eval = this.eval; return copy; }
ConversionResult cr = library.determineNecessaryConversions(function.getName(), function.getType(), args, types, hasArgWithoutType); if (cr.method == null) { return Collections.emptyList();
@Test public void testResolvesClosestType() throws Exception { ElementSymbol e1 = new ElementSymbol("pm1.g1.e1"); //$NON-NLS-1$ //dummy resolve to a byte e1.setType(DataTypeManager.DefaultDataClasses.BYTE); e1.setMetadataID(new Object()); Function function = new Function("abs", new Expression[] {e1}); //$NON-NLS-1$ ResolverVisitor.resolveLanguageObject(function, RealMetadataFactory.example1Cached()); assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, function.getType()); }
ConversionResult cr = library.determineNecessaryConversions(function.getName(), function.getType(), args, types, hasArgWithoutType); if (cr.method == null) { return Collections.emptyList();
ConversionResult cr = library.determineNecessaryConversions(function.getName(), function.getType(), args, types, hasArgWithoutType); if (cr.method == null) { return Collections.emptyList();
return DataTypeManager.DefaultDataClasses.CLOB; case STRING_AGG: return super.getType();
Class<?> targetType = function.getType(); if (fromType == targetType) { return true; //this should be removed in rewrite
@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()); }
@Test public void testUDFResolveOrder() throws Exception { QueryMetadataInterface tm = RealMetadataFactory.fromDDL("create foreign function func(x object) returns object; " + " create foreign function func(x string) returns string;" + " create foreign function func1(x object) returns double;" + " create foreign function func1(x string[]) returns bigdecimal;", "x", "y"); String sql = "func('a')"; Function func = (Function) QueryParser.getQueryParser().parseExpression(sql); ResolverVisitor.resolveLanguageObject(func, tm); assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getArgs()[0].getType()); assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getType()); sql = "func1(('1',))"; func = (Function) QueryParser.getQueryParser().parseExpression(sql); ResolverVisitor.resolveLanguageObject(func, tm); }