public int getPrecision(final Object elementID) throws TeiidComponentException, QueryMetadataException { if(elementID instanceof Column) { return ((Column) elementID).getPrecision(); } else if(elementID instanceof ProcedureParameter) { return ((ProcedureParameter) elementID).getPrecision(); } else { throw createInvalidRecordTypeException(elementID); } }
public int getPrecision(final Object elementID) throws TeiidComponentException, QueryMetadataException { if(elementID instanceof Column) { return ((Column) elementID).getPrecision(); } else if(elementID instanceof ProcedureParameter) { return ((ProcedureParameter) elementID).getPrecision(); } else { throw createInvalidRecordTypeException(elementID); } }
public int getPrecision(final Object elementID) throws TeiidComponentException, QueryMetadataException { if(elementID instanceof Column) { return ((Column) elementID).getPrecision(); } else if(elementID instanceof ProcedureParameter) { return ((ProcedureParameter) elementID).getPrecision(); } else { throw createInvalidRecordTypeException(elementID); } }
@Override protected Column addColumn(ResultSet columns, Table table, MetadataFactory metadataFactory, int rsColumns) throws SQLException { Column c = super.addColumn(columns, table, metadataFactory, rsColumns); if (c.getPrecision() == 0 && "bit".equalsIgnoreCase(c.getNativeType())) { //$NON-NLS-1$ c.setNativeType(TINYINT); } return c; }
public String getCreateTempTableSQL(String name, List<ColumnReference> cols, boolean transactional) { SQLDialect d = getDialect(); StringBuilder sb = new StringBuilder(getCreateTemporaryTableString(transactional)).append(" "); //$NON-NLS-1$ sb.append(name).append(" ("); //$NON-NLS-1$ for (Iterator<ColumnReference> iter = cols.iterator(); iter.hasNext();) { ColumnReference col = iter.next(); sb.append(col.getName()); sb.append(" "); //$NON-NLS-1$ Integer defaultValue = JDBCSQLTypeInfo.getDefaultPrecision(col.getType()); int precision = defaultValue == null?255:defaultValue; int scale = col.getType() == TypeFacility.RUNTIME_TYPES.BIG_DECIMAL?2:0; long length = precision; if (col.getMetadataObject() != null) { precision = col.getMetadataObject().getPrecision(); scale = col.getMetadataObject().getScale(); length = col.getMetadataObject().getLength(); } sb.append(d.getTypeName(TypeFacility.getSQLTypeFromRuntimeType(col.getType()), length, precision, scale)); //sb.append(" NOT NULL"); -- needed if we will add an index if (iter.hasNext()) { sb.append(", "); //$NON-NLS-1$ } } sb.append(") "); if (getCreateTemporaryTablePostfix(transactional) != null) { sb.append(getCreateTemporaryTablePostfix(transactional)); } String sql = sb.toString(); return sql; }
|| runtimeType.equals(DataTypeManager.DefaultDataTypes.BIG_INTEGER)) { if (c.getScale() < 0) { property.setPrecision((int)Math.min(Integer.MAX_VALUE, (long)c.getPrecision() - c.getScale())); } else { property.setPrecision(c.getPrecision()); property.setPrecision(c.getPrecision() == 0?new Integer(4):c.getPrecision());
@Test public void testUDT() throws Exception { String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar OPTIONS (UDT 'NMTOKENS(12,13,11)'))"; Schema s = helpParse(ddl, "model").getSchema(); Map<String, Table> tableMap = s.getTables(); assertTrue("Table not found", tableMap.containsKey("G1")); Table table = tableMap.get("G1"); assertEquals("NMTOKENS", table.getColumns().get(1).getDatatype().getName()); assertEquals(12, table.getColumns().get(1).getLength()); assertEquals(13, table.getColumns().get(1).getPrecision()); assertEquals(11, table.getColumns().get(1).getScale()); }
@Test public void testTypeLength() throws Exception { String ddl = "CREATE FOREIGN PROCEDURE myProc(OUT p1 boolean, p2 varchar, INOUT p3 decimal) " + "RETURNS (r1 varchar(10), r2 decimal(11,2), r3 object(1), r4 clob(10000))" + "OPTIONS(RANDOM 'any', UUID 'uuid', NAMEINSOURCE 'nis', ANNOTATION 'desc', UPDATECOUNT '2');"; Schema s = helpParse(ddl, "model").getSchema(); Procedure proc = s.getProcedure("myProc"); assertNotNull(proc); List<Column> cols = proc.getResultSet().getColumns(); assertEquals(10, cols.get(0).getLength()); assertEquals(11, cols.get(1).getPrecision()); assertEquals(1, cols.get(2).getLength()); assertEquals(10000, cols.get(3).getLength()); }
@Test public void testDefaultPrecision() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(e4 decimal)"; Schema s = helpParse(ddl, "model").getSchema(); Map<String, Table> tableMap = s.getTables(); assertTrue("Table not found", tableMap.containsKey("G1")); Table table = tableMap.get("G1"); Column e4 = table.getColumns().get(0); assertEquals("e4", e4.getName()); assertEquals("bigdecimal", e4.getDatatype().getName()); assertEquals(false, e4.isAutoIncremented()); assertEquals(Short.MAX_VALUE, e4.getPrecision()); assertEquals(Short.MAX_VALUE/2, e4.getScale()); assertEquals(SearchType.Searchable, e4.getSearchType()); }
private Column addColumn(MetadataFactory mf, Table table, Column property, String newName) { Column c = mf.addColumn(newName, property.getRuntimeType(),table); c.setUpdatable(true); c.setNullType(property.getNullType()); c.setLength(property.getLength()); c.setPrecision(property.getPrecision()); c.setScale(property.getScale()); c.setDefaultValue(property.getDefaultValue()); c.setProperty("MIME-TYPE", c.getProperty("MIME-TYPE", false)); c.setProperty(BaseColumn.SPATIAL_SRID, property.getProperty(BaseColumn.SPATIAL_SRID, false)); c.setProperty("NATIVE_TYPE", property.getProperty("NATIVE_TYPE", false)); return c; }
@Test public void testColumnPrecisionScale() { Column c = new Column(); Datatype datatype = new Datatype(); datatype.setName("bigdecimal"); c.setDatatype(datatype); c.setPrecision(0); c.setScale(2); assertEquals(2, c.getScale()); assertEquals(BaseColumn.DEFAULT_PRECISION, c.getPrecision()); }
private void copyExpressionMetadata(Expression toCopy, QueryMetadataInterface metadata, Column column) throws QueryMetadataException, TeiidComponentException { //determine the column metadata toCopy = SymbolMap.getExpression(toCopy); boolean metadataSet = false; if (toCopy instanceof ElementSymbol) { Object mid = ((ElementSymbol) toCopy).getMetadataID(); if (mid instanceof Column) { metadataSet = true; Column other = (Column)mid; column.setCaseSensitive(other.isCaseSensitive()); column.setCharOctetLength(other.getCharOctetLength()); column.setCurrency(other.isCurrency()); column.setFixedLength(other.isFixedLength()); column.setFormat(other.getFormat()); column.setLength(other.getLength()); column.setNullType(other.getNullType()); column.setPrecision(other.getPrecision()); column.setRadix(other.getRadix()); column.setScale(other.getScale()); column.setSigned(other.isSigned()); } } if (!metadataSet) { MetaDataProcessor.setColumnMetadata(column, toCopy, metadata); } }
private void copyExpressionMetadata(Expression toCopy, QueryMetadataInterface metadata, Column column) throws QueryMetadataException, TeiidComponentException { //determine the column metadata toCopy = SymbolMap.getExpression(toCopy); boolean metadataSet = false; if (toCopy instanceof ElementSymbol) { Object mid = ((ElementSymbol) toCopy).getMetadataID(); if (mid instanceof Column) { metadataSet = true; Column other = (Column)mid; column.setCaseSensitive(other.isCaseSensitive()); column.setCharOctetLength(other.getCharOctetLength()); column.setCurrency(other.isCurrency()); column.setFixedLength(other.isFixedLength()); column.setFormat(other.getFormat()); column.setLength(other.getLength()); column.setNullType(other.getNullType()); column.setPrecision(other.getPrecision()); column.setRadix(other.getRadix()); column.setScale(other.getScale()); column.setSigned(other.isSigned()); } } if (!metadataSet) { MetaDataProcessor.setColumnMetadata(column, toCopy, metadata); } }
assertEquals(14, e3.getPrecision()); assertEquals(5, e3.getScale());
assertEquals(NullType.Nullable, e2.getNullType()); assertEquals(10, e2.getLength()); assertEquals(0, e2.getPrecision()); assertEquals("bigdecimal", e4.getDatatype().getName()); assertEquals(false, e4.isAutoIncremented()); assertEquals(12, e4.getPrecision()); assertEquals(3, e4.getScale()); assertEquals(SearchType.Unsearchable, e4.getSearchType());
assertEquals(NullType.Nullable, e2.getNullType()); assertEquals(10, e2.getLength()); assertEquals(0, e2.getPrecision()); assertEquals("bigdecimal", e4.getDatatype().getName()); assertEquals(false, e4.isAutoIncremented()); assertEquals(12, e4.getPrecision()); assertEquals(3, e4.getScale()); assertEquals(SearchType.Searchable, e4.getSearchType());
assertEquals(NullType.Nullable, e2.getNullType()); assertEquals(10, e2.getLength()); assertEquals(0, e2.getPrecision());