private Object buildArray(java.sql.Array array, StatementContext ctx) throws SQLException { if (!UNSUPPORTED_TYPES.contains(array.getBaseType())) { try { Object ary = array.getArray(); if (componentType.equals(ary.getClass().getComponentType())) { return ary; } } catch (SQLFeatureNotSupportedException ignore) {} } UNSUPPORTED_TYPES.add(array.getBaseType()); return buildFromResultSet(array, ctx); }
public static PDataType fromLiteral(Object value) { if (value == null) { return null; } for (PDataType type : PDataType.values()) { if (type.isArrayType()) { if (value instanceof PhoenixArray) { PhoenixArray arr = (PhoenixArray)value; if ((type.getSqlType() == arr.baseType.sqlType + PDataType.ARRAY_TYPE_BASE) && type.getJavaClass().isInstance(value)) { return type; } } else { Array arr = (Array) value; try { // Does the array's component type make sense for what we were told it is if (arr.getBaseType() == type.getSqlType() - PDataType.ARRAY_TYPE_BASE) { return type; } } catch (SQLException e) { /* Passthrough to fail */ } } } else { if (type.getJavaClass().isInstance(value)) { return type; } } } throw new UnsupportedOperationException("Unsupported literal value [" + value + "] of type " + value.getClass().getName()); }
@Override public Integer call() throws SQLException { return array.getBaseType(); } });
public static List<String> getStringList(final ResultSet rs, final int columnIndex) throws SQLException { final Array ary = rs.getArray(columnIndex); if (ary != null) { Preconditions.checkArgument(ary.getBaseType() == Types.VARCHAR || ary.getBaseType() == Types.CHAR); return Arrays.asList((String []) ary.getArray()); } return null; }
public static List<Integer> getIntegerList(final ResultSet rs, final int columnIndex) throws SQLException { final Array ary = rs.getArray(columnIndex); if (ary != null) { Preconditions.checkArgument(ary.getBaseType() == Types.INTEGER || ary.getBaseType() == Types.SMALLINT); return Arrays.asList((Integer []) ary.getArray()); } return null; }
/** * Returns an array of Integer or null if the input is null. Null is intentional (not empty list), to be * able to distinguish between null value and empty list in the db. */ public static List<Integer> getIntegerList(final ResultSet rs, final String columnName) throws SQLException { final Array ary = rs.getArray(columnName); if (ary != null) { Preconditions.checkArgument(ary.getBaseType() == Types.INTEGER || ary.getBaseType() == Types.SMALLINT); return Arrays.asList((Integer []) ary.getArray()); } return null; }
/** * Returns an array of Strings or null if the input is null. Null is intentional (not empty list), to be * able to distinguish between null value and empty list in the db. */ public static List<String> getStringList(final ResultSet rs, final String columnName) throws SQLException { final Array ary = rs.getArray(columnName); if (ary != null) { Preconditions.checkArgument(ary.getBaseType() == Types.VARCHAR || ary.getBaseType() == Types.CHAR); return Arrays.asList((String []) ary.getArray()); } return null; }
/** * Returns an array of Long or null if the input is null. Null is intentional (not empty list), to be * able to distinguish between null value and empty list in the db. */ public static List<Long> getLongList(final ResultSet rs, final String columnName) throws SQLException { final Array ary = rs.getArray(columnName); if (ary != null) { Preconditions.checkArgument(ary.getBaseType() == Types.BIGINT); return Arrays.asList((Long []) ary.getArray()); } return null; }
public static List<Long> getLongList(final ResultSet rs, final int columnIndex) throws SQLException { final Array ary = rs.getArray(columnIndex); if (ary != null) { Preconditions.checkArgument(ary.getBaseType() == Types.BIGINT); return Arrays.asList((Long []) ary.getArray()); } return null; } }
/** * Converts an Array into a List using {@link Array#getResultSet()}. This implementation is * recursive and can parse multi-dimensional arrays. */ static List<?> extractUsingResultSet(Array array, Calendar calendar) throws SQLException { ResultSet arrayValues = array.getResultSet(); TreeMap<Integer, Object> map = new TreeMap<>(); while (arrayValues.next()) { // column 1 is the index in the array, column 2 is the value. // Recurse on `getValue` to unwrap nested types correctly. // `j` is zero-indexed and incremented for us, thus we have `1` being used twice. map.put(arrayValues.getInt(1), getValue(arrayValues, array.getBaseType(), 1, calendar)); } // If the result set is not in the same order as the actual Array, TreeMap fixes that. // Need to make a concrete list to ensure Jackson serialization. return new ArrayList<>(map.values()); }
@Override public Serializable[] getArrayResult(Array array) throws SQLException { Serializable[] ids; if (array.getBaseType() == Types.NUMERIC) { long[] longs; try { longs = (long[]) arrayGetLongArrayMethod.invoke(array); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException(e); } ids = new Serializable[longs.length]; for (int i = 0; i < ids.length; i++) { ids[i] = Long.valueOf(longs[i]); } } else { ids = (Serializable[]) array.getArray(); } return ids; }
private QueryResultValueComparator comparatorForArrayElements(Array actualArray) { QueryResultValueComparator elementComparator; try { elementComparator = comparatorForType(JDBCType.valueOf(actualArray.getBaseType()), configuration); } catch (SQLException e) { throw Throwables.propagate(e); } return elementComparator; }
@Override public Annotation mapRow(ResultSet rs, int rowNum) throws SQLException { Integer pre = rs.getInt("pre"); String corpusName = rs.getString("corpus_name"); String type = rs.getString("type"); String namespace = rs.getString("namespace"); String name = rs.getString("name"); String value = rs.getString("value"); Array annotationPathArray = rs.getArray("path_name"); List<String> annotationPath = new LinkedList<>(); if(annotationPathArray.getBaseType() == Types.VARCHAR) { annotationPath = Arrays.asList((String[]) annotationPathArray.getArray()); } return new Annotation(namespace, name, value, type, corpusName, pre, annotationPath); } }
private QueryResultValueComparator comparatorForArrayElements(Array actualArray) { QueryResultValueComparator elementComparator; try { elementComparator = comparatorForType(JDBCType.valueOf(actualArray.getBaseType()), configuration); } catch (SQLException e) { throw Throwables.propagate(e); } return elementComparator; }
/** * Converts an Array into a List using {@link Array#getResultSet()}. This implementation is * recursive and can parse multi-dimensional arrays. */ static List<?> extractUsingResultSet(Array array, Calendar calendar) throws SQLException { ResultSet arrayValues = array.getResultSet(); TreeMap<Integer, Object> map = new TreeMap<>(); while (arrayValues.next()) { // column 1 is the index in the array, column 2 is the value. // Recurse on `getValue` to unwrap nested types correctly. // `j` is zero-indexed and incremented for us, thus we have `1` being used twice. map.put(arrayValues.getInt(1), getValue(arrayValues, array.getBaseType(), 1, calendar)); } // If the result set is not in the same order as the actual Array, TreeMap fixes that. // Need to make a concrete list to ensure Jackson serialization. return new ArrayList<>(map.values()); }
private Object buildArray(java.sql.Array array, StatementContext ctx) throws SQLException { if (!UNSUPPORTED_TYPES.contains(array.getBaseType())) { try { Object ary = array.getArray(); if (componentType.equals(ary.getClass().getComponentType())) { return ary; } } catch (SQLFeatureNotSupportedException swallowed) { // fall through } } UNSUPPORTED_TYPES.add(array.getBaseType()); return buildFromResultSet(array, ctx); }
@Override public Annotation mapRow(ResultSet rs, int rowNum) throws SQLException { Annotation annotation = new Annotation(); annotation.setName(rs.getString("name")); annotation.setPre(rs.getInt("pre")); Array annotationPathArray = rs.getArray("path_name"); List<String> annotationPath = new LinkedList<>(); if(annotationPathArray.getBaseType() == Types.VARCHAR) { annotationPath = Arrays.asList((String[]) annotationPathArray.getArray()); } annotation.setAnnotationPath(annotationPath); return annotation; } }
@Override public void setArray(int parameterIndex, Array x) throws SQLException { setBind(parameterIndex, ClickHouseArrayUtil.arrayToString(x.getArray(), x.getBaseType() != Types.BINARY)); }
@Override public void setArray(int parameterIndex, Array x) throws SQLException { setBind(parameterIndex, ClickHouseArrayUtil.arrayToString(x.getArray(), x.getBaseType() != Types.BINARY)); }
public static PDataType fromLiteral(Object value) { if (value == null) { return null; } for (PDataType type : PDataType.values()) { if (type.isArrayType()) { if (value instanceof PhoenixArray) { PhoenixArray arr = (PhoenixArray)value; if ((type.getSqlType() == arr.baseType.sqlType + PDataType.ARRAY_TYPE_BASE) && type.getJavaClass().isInstance(value)) { return type; } } else { Array arr = (Array) value; try { // Does the array's component type make sense for what we were told it is if (arr.getBaseType() == type.getSqlType() - PDataType.ARRAY_TYPE_BASE) { return type; } } catch (SQLException e) { /* Passthrough to fail */ } } } else { if (type.getJavaClass().isInstance(value)) { return type; } } } throw new UnsupportedOperationException("Unsupported literal value [" + value + "] of type " + value.getClass().getName()); }