Permalink
Browse files

TEIID-5111 treating a 0 length value from designer

  • Loading branch information...
1 parent ec1c533 commit 45068e2d5739827c0d3b142272731cb73fdc879e @shawkins shawkins committed Oct 20, 2017
@@ -1000,5 +1000,16 @@ public static boolean isHashable(Class<?> type) {
}
return Array.newInstance(classType, 0).getClass();
}
+
+ /**
+ * Return true if the type may be defined with a length
+ */
+ public static boolean hasLength(Class<?> classType) {
+ return (DataTypeManager.isLOB(classType)
+ || classType == DefaultDataClasses.OBJECT
+ || classType == DefaultDataClasses.STRING
+ || classType == DefaultDataClasses.VARBINARY
+ || classType == DefaultDataClasses.CHAR);
+ }
}
@@ -24,6 +24,7 @@
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.index.IEntryResult;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.JDBCSQLTypeInfo;
import org.teiid.internal.core.index.Index;
import org.teiid.metadata.*;
import org.teiid.metadata.FunctionMethod.Determinism;
@@ -248,6 +249,16 @@ private void setDataType(BaseColumn baseColumn) {
type = type.substring(0, type.length()-2);
}
baseColumn.setDatatype(dataType, false, arrayDimensions);
+ if (baseColumn.getLength() == 0) {
+ Class<?> baseType = DataTypeManager.getDataTypeClass(type);
+ if (DataTypeManager.hasLength(baseType)) {
+ //designer sends a default length of 0 as a default, but the engine does not expect that generally
+ Integer length = JDBCSQLTypeInfo.getMaxDisplaySize(baseType);
+ if (length != null) {
+ baseColumn.setLength(length);
+ }
+ }
+ }
}
private void getTables(Schema model) {
@@ -21,17 +21,18 @@
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.teiid.cdk.api.TranslationUtility;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.language.ColumnReference;
import org.teiid.language.DerivedColumn;
import org.teiid.language.Select;
-import org.teiid.metadata.Column;
import org.teiid.metadata.BaseColumn.NullType;
+import org.teiid.metadata.Column;
import org.teiid.metadata.Column.SearchType;
+import junit.framework.TestCase;
+
/**
*/
@@ -214,7 +215,7 @@ public void testEnterpriseDataTypes() throws Exception {
null, // minimum value
null, // maximum value
String.class, // java type
- 0, // length
+ DataTypeManager.MAX_STRING_LENGTH, // length
NullType.Nullable, // nullable
6, // position
SearchType.Searchable, // searchable
@@ -21,15 +21,16 @@
import java.sql.Timestamp;
import java.util.List;
-import junit.framework.TestCase;
-
import org.teiid.cdk.api.TranslationUtility;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.language.Argument;
-import org.teiid.language.Call;
import org.teiid.language.Argument.Direction;
-import org.teiid.metadata.ProcedureParameter;
+import org.teiid.language.Call;
import org.teiid.metadata.BaseColumn.NullType;
+import org.teiid.metadata.ProcedureParameter;
+
+import junit.framework.TestCase;
@@ -146,7 +147,7 @@ public void testProcedureWithResultSet() throws Exception {
null, //$NON-NLS-1$
NullType.Nullable,
String.class,
- 0,
+ DataTypeManager.MAX_STRING_LENGTH,
0,
0); //$NON-NLS-1$

0 comments on commit 45068e2

Please sign in to comment.