Search in sources :

Example 1 with VerticaColumnType

use of com.github.jcustenborder.vertica.VerticaColumnType in project kafka-connect-vertica by jcustenborder.

the class VerticaSinkTask method configureBuilder.

VerticaStreamWriterBuilder configureBuilder(Connection connection, final String tableName) throws ExecutionException {
    return this.builderCache.get(tableName, () -> {
        VerticaStreamWriterBuilder builder = new VerticaStreamWriterBuilder();
        builder.compressionType(this.config.compressionType);
        builder.loadMethod(this.config.loadMethod);
        builder.table(tableName);
        log.trace("configureBuilder() - Finding columns for '{}'", tableName);
        List<String> fields = new ArrayList<>();
        try (PreparedStatement statement = connection.prepareStatement(SQL)) {
            statement.setString(1, tableName);
            try (ResultSet results = statement.executeQuery()) {
                while (results.next()) {
                    String columnName = results.getString(1);
                    fields.add(columnName);
                    String dataType = results.getString(2);
                    Matcher matcher = PATTERN.matcher(dataType);
                    if (!matcher.find()) {
                        log.warn("Could not match '{}' for column '{}'", dataType, columnName);
                        continue;
                    }
                    String stype = matcher.group(0).toUpperCase();
                    VerticaColumnType type = VerticaColumnType.valueOf(stype);
                    log.info("configureBuilder() - '{}' = {}", columnName, type);
                    builder.column(columnName, type);
                }
            }
        }
        return builder;
    });
}
Also used : VerticaStreamWriterBuilder(com.github.jcustenborder.vertica.VerticaStreamWriterBuilder) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) VerticaColumnType(com.github.jcustenborder.vertica.VerticaColumnType)

Aggregations

VerticaColumnType (com.github.jcustenborder.vertica.VerticaColumnType)1 VerticaStreamWriterBuilder (com.github.jcustenborder.vertica.VerticaStreamWriterBuilder)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1