public JDBCConverter getConverter(final Field f) { return getConverter(f, f.pos() + 1); }
public JDBCConverter getConverter(final Field f) { return getConverter(f, f.pos() + 1); }
@Override public void setSchema(Schema schema) { this.schema = schema; names = new String[getSchema().getFields().size()]; fieldConverter = new AvroConverter[names.length]; for (int j = 0; j < names.length; j++) { Field f = getSchema().getFields().get(j); names[j] = f.name(); JDBCAvroRegistry.JDBCConverter jdbcConverter = getRegistry().getConverter(f); if (influencer != null) { jdbcConverter.setInfluencer(influencer); } fieldConverter[j] = jdbcConverter; } }
@Override public void setSchema(Schema schema) { this.schema = schema; names = new String[getSchema().getFields().size()]; fieldConverter = new AvroConverter[names.length]; for (int j = 0; j < names.length; j++) { Field f = getSchema().getFields().get(j); names[j] = f.name(); JDBCAvroRegistry.JDBCConverter jdbcConverter = getRegistry().getConverter(f); if (influencer != null) { jdbcConverter.setInfluencer(influencer); } fieldConverter[j] = jdbcConverter; } }
@Override public JDBCConverter getConverter(final Field f) { final Schema basicSchema = AvroUtils.unwrapIfNullable(f.schema()); return null == basicSchema.getLogicalType() ? super.getConverter(f) : new JDBCConverter() { @Override public Object convertToAvro(ResultSet value) { int index = f.pos() + 1; try { if (basicSchema.getLogicalType() == LogicalTypes.date()) { // Snowflake stores the value as the number of days. So it is possible to retrieve that as an // int value instead of converting it to Date first and then to days from milliseconds. If we // convert it to date, Snowflake jdbc shifts the time to 00:00 in current timezone. Object date = value.getObject(index); return (date != null) ? value.getInt(index) : null; } else if (basicSchema.getLogicalType() == LogicalTypes.timeMillis()) { java.sql.Time time = value.getTime(index); return (time != null) ? (int) time.getTime() : null; } else { java.sql.Timestamp timestamp = value.getTimestamp(index); return (timestamp != null) ? timestamp.getTime() : null; } } catch (SQLException e) { throw new ComponentException(e); } } }; } }
@Override public JDBCConverter getConverter(final Field f) { final Schema basicSchema = AvroUtils.unwrapIfNullable(f.schema()); return null == basicSchema.getLogicalType() ? super.getConverter(f) : new JDBCConverter() { @Override public Object convertToAvro(ResultSet value) { int index = f.pos() + 1; try { if (basicSchema.getLogicalType() == LogicalTypes.date()) { // Snowflake stores the value as the number of days. So it is possible to retrieve that as an // int value instead of converting it to Date first and then to days from milliseconds. If we // convert it to date, Snowflake jdbc shifts the time to 00:00 in current timezone. Object date = value.getObject(index); return (date != null) ? value.getInt(index) : null; } else if (basicSchema.getLogicalType() == LogicalTypes.timeMillis()) { java.sql.Time time = value.getTime(index); return (time != null) ? (int) time.getTime() : null; } else { java.sql.Timestamp timestamp = value.getTimestamp(index); return (timestamp != null) ? timestamp.getTime() : null; } } catch (SQLException e) { throw new ComponentException(e); } } }; } }
return null == basicSchema.getLogicalType() ? super.getConverter(f) : new JDBCConverter() {