/** * Gets AvaticaType carrying both JDBC {@code java.sql.Type.*} type code * and SQL type name for given SQL type name. */ private static AvaticaType getAvaticaType(String sqlTypeName) { final int jdbcTypeId = Types.getJdbcTypeCode(sqlTypeName); return ColumnMetaData.scalar( jdbcTypeId, sqlTypeName, Rep.BOOLEAN /* dummy value, unused */ ); }
/** * Gets AvaticaType carrying both JDBC {@code java.sql.Type.*} type code * and SQL type name for given RPC-level type (from batch schema). */ private static AvaticaType getAvaticaType( MajorType rpcDateType ) { final String sqlTypeName = Types.getSqlTypeName( rpcDateType ); final int jdbcTypeId = Types.getJdbcTypeCode( sqlTypeName ); return ColumnMetaData.scalar( jdbcTypeId, sqlTypeName, Rep.BOOLEAN /* dummy value, unused */ ); }
protected static ColumnMetaData drillColumnMetaData(String name, int index, Class<?> type, boolean notNullable) { TypeInfo pair = TypeInfo.get(type); ColumnMetaData.Rep rep = ColumnMetaData.Rep.VALUE_MAP.get(type); ColumnMetaData.AvaticaType scalarType = ColumnMetaData.scalar(pair.sqlType, pair.sqlTypeName, rep); return new ColumnMetaData( index, false, true, false, false, notNullable ? DatabaseMetaData.columnNoNulls : DatabaseMetaData.columnNullable, true, -1, name, name, null, 0, 0, null, null, scalarType, true, false, false, scalarType.columnClassName()); }
@Override public QueryResult executeQuery(String sql, List<Object> paramValues, Map<String, String> queryToggles) throws IOException { List<Object> data = new ArrayList<Object>(); Object[] row = new Object[] { "foo", "bar", "tool" }; data.add(row); List<ColumnMetaData> meta = new ArrayList<ColumnMetaData>(); meta.add(ColumnMetaData.dummy(ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true)); meta.add(ColumnMetaData.dummy(ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true)); meta.add(ColumnMetaData.dummy(ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true)); return new QueryResult(meta, data); }
private IRemoteClient.QueryResult getMockResult() { ArrayList<ColumnMetaData> columnMeta = new ArrayList<>(); columnMeta.add(new ColumnMetaData(0, false, true, false, false, 1, true, 1, "VAL", "VAL", null, 10, 0, null, null, ColumnMetaData.scalar(Types.INTEGER, "INTEGER", ColumnMetaData.Rep.INTEGER), true, false, false, "java.lang.Integer")); ArrayList<Object> list = new ArrayList<>(); list.add(new Object[]{1}); return new IRemoteClient.QueryResult(columnMeta, list); } }
private List<ColumnMetaData> convertColumnMeta(SQLResponseStub queryResp) { List<ColumnMetaData> metas = new ArrayList<ColumnMetaData>(); for (int i = 0; i < queryResp.getColumnMetas().size(); i++) { SQLResponseStub.ColumnMetaStub scm = queryResp.getColumnMetas().get(i); Class columnClass = convertType(scm.getColumnType()); ScalarType type = ColumnMetaData.scalar(scm.getColumnType(), scm.getColumnTypeName(), Rep.of(columnClass)); ColumnMetaData meta = new ColumnMetaData(i, scm.isAutoIncrement(), scm.isCaseSensitive(), scm.isSearchable(), scm.isCurrency(), scm.getIsNullable(), scm.isSigned(), scm.getDisplaySize(), scm.getLabel(), scm.getName(), scm.getSchemaName(), scm.getPrecision(), scm.getScale(), scm.getTableName(), scm.getSchemaName(), type, scm.isReadOnly(), scm.isWritable(), scm.isWritable(), columnClass.getCanonicalName()); metas.add(meta); } return metas; }
RelDataTypeField field = fieldList.get(i); final ColumnMetaData.Rep rep = QueryMaker.rep(field.getType().getSqlTypeName()); final ColumnMetaData.ScalarType columnType = ColumnMetaData.scalar( field.getType().getSqlTypeName().getJdbcOrdinal(), field.getType().getSqlTypeName().getName(),
/** * Gets AvaticaType carrying both JDBC {@code java.sql.Type.*} type code * and SQL type name for given SQL type name. */ private static AvaticaType getAvaticaType(String sqlTypeName) { final int jdbcTypeId = Types.getJdbcTypeCode(sqlTypeName); return ColumnMetaData.scalar( jdbcTypeId, sqlTypeName, Rep.BOOLEAN /* dummy value, unused */ ); }
/** * Gets AvaticaType carrying both JDBC {@code java.sql.Type.*} type code * and SQL type name for given SQL type name. */ private static AvaticaType getAvaticaType(String sqlTypeName) { final int jdbcTypeId = Types.getJdbcTypeCode(sqlTypeName); return ColumnMetaData.scalar( jdbcTypeId, sqlTypeName, Rep.BOOLEAN /* dummy value, unused */ ); }
public static ColumnMetaData columnMetaData(String name, int index, Class<?> type, int columnNullable) { TypeInfo pair = TypeInfo.m.get(type); ColumnMetaData.Rep rep = ColumnMetaData.Rep.VALUE_MAP.get(type); ColumnMetaData.AvaticaType scalarType = ColumnMetaData.scalar(pair.sqlType, pair.sqlTypeName, rep); return columnMetaData(name, index, scalarType, columnNullable); }
public static ColumnMetaData columnMetaData(String name, int index, Class<?> type, int columnNullable) { TypeInfo pair = TypeInfo.m.get(type); ColumnMetaData.Rep rep = ColumnMetaData.Rep.VALUE_MAP.get(type); ColumnMetaData.AvaticaType scalarType = ColumnMetaData.scalar(pair.sqlType, pair.sqlTypeName, rep); return columnMetaData(name, index, scalarType, columnNullable); }
public static ColumnMetaData columnMetaData(String name, int index, Class<?> type) { TypeInfo pair = TypeInfo.m.get(type); ColumnMetaData.Rep rep = ColumnMetaData.Rep.VALUE_MAP.get(type); ColumnMetaData.AvaticaType scalarType = ColumnMetaData.scalar(pair.sqlType, pair.sqlTypeName, rep); return new ColumnMetaData( index, false, true, false, false, pair.primitive ? DatabaseMetaData.columnNullable : DatabaseMetaData.columnNoNulls, true, -1, name, name, null, 0, 0, null, null, scalarType, true, false, false, scalarType.columnClassName()); }
/** * Gets AvaticaType carrying both JDBC {@code java.sql.Type.*} type code * and SQL type name for given RPC-level type (from batch schema). */ private static AvaticaType getAvaticaType( MajorType rpcDateType ) { final String sqlTypeName = Types.getSqlTypeName( rpcDateType ); final int jdbcTypeId = Types.getJdbcTypeCode( sqlTypeName ); return ColumnMetaData.scalar( jdbcTypeId, sqlTypeName, Rep.BOOLEAN /* dummy value, unused */ ); }
/** * Gets AvaticaType carrying both JDBC {@code java.sql.Type.*} type code * and SQL type name for given RPC-level type (from batch schema). */ private static AvaticaType getAvaticaType( MajorType rpcDateType ) { final String sqlTypeName = Types.getSqlTypeName( rpcDateType ); final int jdbcTypeId = Types.getJdbcTypeCode( sqlTypeName ); return ColumnMetaData.scalar( jdbcTypeId, sqlTypeName, Rep.BOOLEAN /* dummy value, unused */ ); }
protected static ColumnMetaData drillColumnMetaData(String name, int index, Class<?> type, boolean notNullable) { TypeInfo pair = TypeInfo.get(type); ColumnMetaData.Rep rep = ColumnMetaData.Rep.VALUE_MAP.get(type); ColumnMetaData.AvaticaType scalarType = ColumnMetaData.scalar(pair.sqlType, pair.sqlTypeName, rep); return new ColumnMetaData( index, false, true, false, false, notNullable ? DatabaseMetaData.columnNoNulls : DatabaseMetaData.columnNullable, true, -1, name, name, null, 0, 0, null, null, scalarType, true, false, false, scalarType.columnClassName()); }
@Override public void testGetArray(ResultSet resultSet) throws SQLException { ColumnMetaData.ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", ColumnMetaData.Rep.INTEGER); Array expectedArray = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()).createArray( intType, Arrays.asList(1, 2, 3)); assertTrue(ArrayImpl.equalContents(expectedArray, g.getArray(resultSet))); } }
@Override public void testGetArray(ResultSet resultSet) throws SQLException { ColumnMetaData.ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", ColumnMetaData.Rep.INTEGER); Array expectedArray = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()).createArray( intType, Arrays.asList(1, 2, 3)); assertTrue(ArrayImpl.equalContents(expectedArray, g.getArray(resultSet))); } }
public static AvaticaType fromProto(Common.AvaticaType proto) { Common.Rep repProto = proto.getRep(); Rep rep = Rep.valueOf(repProto.name()); AvaticaType type; if (proto.hasComponent()) { // ArrayType // recurse on the type for the array elements AvaticaType nestedType = AvaticaType.fromProto(proto.getComponent()); type = ColumnMetaData.array(nestedType, proto.getName(), rep); } else if (proto.getColumnsCount() > 0) { // StructType List<ColumnMetaData> columns = new ArrayList<>(proto.getColumnsCount()); for (Common.ColumnMetaData protoColumn : proto.getColumnsList()) { columns.add(ColumnMetaData.fromProto(protoColumn)); } type = ColumnMetaData.struct(columns); } else { // ScalarType type = ColumnMetaData.scalar(proto.getId(), proto.getName(), rep); } return type; }
@Test public void testArrays() { List<Object> serialObj = Arrays.<Object>asList(1, 2, 3, 4); ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); ScalarType scalarType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER); Array a1 = factory.createArray(scalarType, serialObj); TypedValue tv1 = TypedValue.ofJdbc(Rep.ARRAY, a1, Unsafe.localCalendar()); Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObj.getClass(), jdbcObj instanceof Array); Object localObj = tv1.toLocal(); assertTrue("The local object is an " + localObj.getClass(), localObj instanceof List); Common.TypedValue protoTv1 = tv1.toProto(); assertEquals(serialObj.size(), protoTv1.getArrayValueCount()); TypedValue tv1Copy = TypedValue.fromProto(protoTv1); Object jdbcObjCopy = tv1Copy.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObjCopy.getClass(), jdbcObjCopy instanceof Array); Object localObjCopy = tv1Copy.toLocal(); assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List); } }
@Test public void testArrays() { List<Object> serialObj = Arrays.<Object>asList(1, 2, 3, 4); ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); ScalarType scalarType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER); Array a1 = factory.createArray(scalarType, serialObj); TypedValue tv1 = TypedValue.ofJdbc(Rep.ARRAY, a1, Unsafe.localCalendar()); Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObj.getClass(), jdbcObj instanceof Array); Object localObj = tv1.toLocal(); assertTrue("The local object is an " + localObj.getClass(), localObj instanceof List); Common.TypedValue protoTv1 = tv1.toProto(); assertEquals(serialObj.size(), protoTv1.getArrayValueCount()); TypedValue tv1Copy = TypedValue.fromProto(protoTv1); Object jdbcObjCopy = tv1Copy.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObjCopy.getClass(), jdbcObjCopy instanceof Array); Object localObjCopy = tv1Copy.toLocal(); assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List); } }