/** * Get type of parameter * @return Type name * @see org.teiid.core.types.DataTypeManager.DefaultDataTypes * @deprecated use {@link #getRuntimeType()} */ public String getType() { return getRuntimeType(); }
/** * Return hash code for this parameter. The hash code is based only * on the type of the parameter. Changing the type of the parameter * after placing this object in a hashed collection will likely cause * the object to be lost. * @return Hash code */ public int hashCode() { if(this.getRuntimeType() == null) { return 0; } return this.getRuntimeType().hashCode(); }
/** * Return string version for debugging purposes * @return String representation of function parameter */ public String toString() { return getRuntimeType() + (isVarArg?"... ":" ") + super.toString(); //$NON-NLS-1$ //$NON-NLS-2$ }
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); } }
public FunctionDescriptor[] getConverts(FunctionMethod method, Class<?>[] types) { final List<FunctionParameter> methodTypes = method.getInputParameters(); FunctionDescriptor[] result = new FunctionDescriptor[types.length]; for(int i = 0; i < types.length; i++) { //treat all varags as the same type final String tmpTypeName = methodTypes.get(Math.min(i, methodTypes.size() - 1)).getRuntimeType(); Class<?> targetType = DataTypeManager.getDataTypeClass(tmpTypeName); Class<?> sourceType = types[i]; if (sourceType == null) { result[i] = findTypedConversionFunction(DataTypeManager.DefaultDataClasses.NULL, targetType); } else if (sourceType != targetType){ if (isVarArgArrayParam(method, types, i, targetType)) { //vararg array parameter continue; } result[i] = findTypedConversionFunction(sourceType, targetType); } } return result; }
public FunctionDescriptor[] getConverts(FunctionMethod method, Class<?>[] types) { final List<FunctionParameter> methodTypes = method.getInputParameters(); FunctionDescriptor[] result = new FunctionDescriptor[types.length]; for(int i = 0; i < types.length; i++) { //treat all varags as the same type final String tmpTypeName = methodTypes.get(Math.min(i, methodTypes.size() - 1)).getRuntimeType(); Class<?> targetType = DataTypeManager.getDataTypeClass(tmpTypeName); Class<?> sourceType = types[i]; if (sourceType == null) { result[i] = findTypedConversionFunction(DataTypeManager.DefaultDataClasses.NULL, targetType); } else if (sourceType != targetType){ if (isVarArgArrayParam(method, types, i, targetType)) { //vararg array parameter continue; } result[i] = findTypedConversionFunction(sourceType, targetType); } } return result; }
public FunctionDescriptor[] getConverts(FunctionMethod method, Class<?>[] types) { final List<FunctionParameter> methodTypes = method.getInputParameters(); FunctionDescriptor[] result = new FunctionDescriptor[types.length]; for(int i = 0; i < types.length; i++) { //treat all varags as the same type final String tmpTypeName = methodTypes.get(Math.min(i, methodTypes.size() - 1)).getRuntimeType(); Class<?> targetType = DataTypeManager.getDataTypeClass(tmpTypeName); Class<?> sourceType = types[i]; if (sourceType == null) { result[i] = findTypedConversionFunction(DataTypeManager.DefaultDataClasses.NULL, targetType); } else if (sourceType != targetType){ if (isVarArgArrayParam(method, types, i, targetType)) { //vararg array parameter continue; } result[i] = findTypedConversionFunction(sourceType, targetType); } } return result; }
&& "boolean".equals(((Function)left).getMetadataObject().getOutputParameter().getRuntimeType())) { visitComparisonWithBooleanFunction(obj);
types = new Class<?>[inputParams.size()]; for(int i=0; i<inputParams.size(); i++) { String typeName = inputParams.get(i).getRuntimeType(); Class<?> clazz = DataTypeManager.getDataTypeClass(typeName); types[i] = clazz;
@Override public void fillRow(List<Object> row, FunctionParameter param, VDBMetaData vdb, TransformationMetadata metadata, CommandContext cc, SimpleIterator<FunctionParameter> iter) { row.add(vdb.getName()); FunctionMethod parent = ((ExpandingSimpleIterator<FunctionMethod, FunctionParameter>)iter).getCurrentParent(); if (parent.getParent() == null) { row.add(CoreConstants.SYSTEM_MODEL); } else { row.add(parent.getParent().getName()); } row.add(parent.getName()); row.add(parent.getUUID()); row.add(param.getName()); row.add(param.getRuntimeType()); row.add(param.getPosition()); row.add(param.getPosition()==0?"ReturnValue":"In"); //$NON-NLS-1$ //$NON-NLS-2$ row.add(param.getPrecision()); row.add(param.getLength()); row.add(param.getScale()); row.add(param.getRadix()); row.add(param.getNullType().toString()); row.add(param.getUUID()); row.add(param.getAnnotation()); addTypeInfo(row, param, param.getDatatype()); }
@Override public void fillRow(List<Object> row, FunctionParameter param, VDBMetaData vdb, TransformationMetadata metadata, CommandContext cc, SimpleIterator<FunctionParameter> iter) { row.add(vdb.getName()); FunctionMethod parent = ((ExpandingSimpleIterator<FunctionMethod, FunctionParameter>)iter).getCurrentParent(); if (parent.getParent() == null) { row.add(CoreConstants.SYSTEM_MODEL); } else { row.add(parent.getParent().getName()); } row.add(parent.getName()); row.add(parent.getUUID()); row.add(param.getName()); row.add(param.getRuntimeType()); row.add(param.getPosition()); row.add(param.getPosition()==0?"ReturnValue":"In"); //$NON-NLS-1$ //$NON-NLS-2$ row.add(param.getPrecision()); row.add(param.getLength()); row.add(param.getScale()); row.add(param.getRadix()); row.add(param.getNullType().toString()); row.add(param.getUUID()); row.add(param.getAnnotation()); addTypeInfo(row, param, param.getDatatype()); }
@Override public void fillRow(List<Object> row, FunctionParameter param, VDBMetaData vdb, TransformationMetadata metadata, CommandContext cc, SimpleIterator<FunctionParameter> iter) { row.add(vdb.getName()); FunctionMethod parent = ((ExpandingSimpleIterator<FunctionMethod, FunctionParameter>)iter).getCurrentParent(); if (parent.getParent() == null) { row.add(CoreConstants.SYSTEM_MODEL); } else { row.add(parent.getParent().getName()); } row.add(parent.getName()); row.add(parent.getUUID()); row.add(param.getName()); row.add(param.getRuntimeType()); row.add(param.getPosition()); row.add(param.getPosition()==0?"ReturnValue":"In"); //$NON-NLS-1$ //$NON-NLS-2$ row.add(param.getPrecision()); row.add(param.getLength()); row.add(param.getScale()); row.add(param.getRadix()); row.add(param.getNullType().toString()); row.add(param.getUUID()); row.add(param.getAnnotation()); addTypeInfo(row, param, param.getDatatype()); }
@Test public void testMixedCaseTypes() throws Exception { String ddl = "CREATE FUNCTION SourceFunc(flag Boolean) RETURNS varchaR options (UUID 'z')"; Schema s = helpParse(ddl, "model").getSchema(); FunctionMethod fm = s.getFunction("z"); assertEquals("boolean", fm.getInputParameters().get(0).getRuntimeType()); }
@Test public void testFunction() throws Exception { String ddl = "CREATE DATABASE FOO;" + "USE DATABASE FOO ;" + "CREATE FOREIGN DATA WRAPPER postgresql;" + "CREATE SERVER pgsql TYPE 'custom' FOREIGN DATA WRAPPER postgresql OPTIONS (\"jndi-name\" 'jndiname');" + "CREATE SCHEMA test SERVER pgsql;" + "SET SCHEMA test;" + "CREATE FOREIGN FUNCTION SourceFunc(flag Boolean) RETURNS varchar"; FunctionMethod method = null; Database db = helpParse(ddl); Schema s = db.getSchema("test"); for (FunctionMethod fm : s.getFunctions().values()) { if (fm.getName().equalsIgnoreCase("SourceFunc")) { method = fm; break; } } assertNotNull(method); assertEquals("boolean", method.getInputParameters().get(0).getRuntimeType()); }
validateFunctionParameter(param); param.setPosition(i+1); MetadataFactory.setDataType(param.getRuntimeType(), param, runtimeTypeMap, true); param.getUUID(); MetadataFactory.setDataType(method.getOutputParameter().getRuntimeType(), method.getOutputParameter(), runtimeTypeMap, true); } catch(FunctionMetadataException e) { updateReport(report, method, e.getMessage());
validateFunctionParameter(param); param.setPosition(i+1); MetadataFactory.setDataType(param.getRuntimeType(), param, runtimeTypeMap, true); param.getUUID(); MetadataFactory.setDataType(method.getOutputParameter().getRuntimeType(), method.getOutputParameter(), runtimeTypeMap, true); } catch(FunctionMetadataException e) { updateReport(report, method, e.getMessage());
validateFunctionParameter(param); param.setPosition(i+1); MetadataFactory.setDataType(param.getRuntimeType(), param, runtimeTypeMap, true); param.getUUID(); MetadataFactory.setDataType(method.getOutputParameter().getRuntimeType(), method.getOutputParameter(), runtimeTypeMap, true); } catch(FunctionMetadataException e) { updateReport(report, method, e.getMessage());
@Test public void testUDF() throws Exception { String ddl = "CREATE VIRTUAL FUNCTION SourceFunc(flag boolean, msg varchar) RETURNS varchar " + "OPTIONS(CATEGORY 'misc', DETERMINISM 'DETERMINISTIC', " + "\"NULL-ON-NULL\" 'true', JAVA_CLASS 'foo', JAVA_METHOD 'bar', RANDOM 'any', UUID 'x')"; Schema s = helpParse(ddl, "model").getSchema(); FunctionMethod fm = s.getFunction("x"); 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()); assertEquals(FunctionMethod.Determinism.DETERMINISTIC, fm.getDeterminism()); assertEquals("misc", fm.getCategory()); assertEquals(true, fm.isNullOnNull()); assertEquals("foo", fm.getInvocationClass()); assertEquals("bar", fm.getInvocationMethod()); assertEquals("any", fm.getProperties().get("RANDOM")); }
@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()); }