Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosmarxm committed Oct 14, 2022
1 parent 634ae87 commit 491f5ff
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ public static Map<String, Object> flatten(final JsonNode node, final Boolean app
}

/**
* Flattens an ObjectNode, or dumps it into a {null: value} map if it's not an object.
* New usage of this function is best to explicitly declare the intended array mode.
* This version is provided for backward compatibility.
* Flattens an ObjectNode, or dumps it into a {null: value} map if it's not an object. New usage of
* this function is best to explicitly declare the intended array mode. This version is provided for
* backward compatibility.
*/
public static Map<String, Object> flatten(final JsonNode node) {
return flatten(node, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ void testToObject() {

assertEquals(
Lists.newArrayList(expected),
Jsons.object(Jsons.jsonNode(Lists.newArrayList(expected)), new TypeReference<List<ToClass>>() {
}));
Jsons.object(Jsons.jsonNode(Lists.newArrayList(expected)), new TypeReference<List<ToClass>>() {}));

assertEquals(
new ToClass(),
Expand All @@ -179,8 +178,7 @@ void testTryToObject() {

assertEquals(
Optional.of(expected),
Jsons.tryObject(Jsons.deserialize(SERIALIZED_JSON), new TypeReference<ToClass>() {
}));
Jsons.tryObject(Jsons.deserialize(SERIALIZED_JSON), new TypeReference<ToClass>() {}));

final ToClass emptyExpected = new ToClass();
assertEquals(
Expand All @@ -189,8 +187,7 @@ void testTryToObject() {

assertEquals(
Optional.of(emptyExpected),
Jsons.tryObject(Jsons.deserialize("{\"str1\":\"abc\"}"), new TypeReference<ToClass>() {
}));
Jsons.tryObject(Jsons.deserialize("{\"str1\":\"abc\"}"), new TypeReference<ToClass>() {}));

}

Expand Down Expand Up @@ -273,9 +270,9 @@ void testGetEstimatedByteSize() {
void testFlatten__noArrays() {
final JsonNode json = Jsons.deserialize("{ \"abc\": { \"def\": \"ghi\" }, \"jkl\": true, \"pqr\": 1 }");
Map<String, Object> expected = Stream.of(new Object[][] {
{ "abc.def", "ghi" },
{ "jkl", true },
{ "pqr", 1 },
{"abc.def", "ghi"},
{"jkl", true},
{"pqr", 1},
}).collect(Collectors.toMap(data -> (String) data[0], data -> data[1]));
assertEquals(expected, Jsons.flatten(json, false));
}
Expand All @@ -285,9 +282,9 @@ void testFlatten__withArraysNoApplyFlatten() {
final JsonNode json = Jsons
.deserialize("{ \"abc\": [{ \"def\": \"ghi\" }, { \"fed\": \"ihg\" }], \"jkl\": true, \"pqr\": 1 }");
Map<String, Object> expected = Stream.of(new Object[][] {
{ "abc", "[{\"def\":\"ghi\"},{\"fed\":\"ihg\"}]" },
{ "jkl", true },
{ "pqr", 1 },
{"abc", "[{\"def\":\"ghi\"},{\"fed\":\"ihg\"}]"},
{"jkl", true},
{"pqr", 1},
}).collect(Collectors.toMap(data -> (String) data[0], data -> data[1]));
assertEquals(expected, Jsons.flatten(json, false));
}
Expand All @@ -297,22 +294,22 @@ void testFlatten__checkBackwardCompatiblity() {
final JsonNode json = Jsons
.deserialize("{ \"abc\": [{ \"def\": \"ghi\" }, { \"fed\": \"ihg\" }], \"jkl\": true, \"pqr\": 1 }");
Map<String, Object> expected = Stream.of(new Object[][] {
{ "abc", "[{\"def\":\"ghi\"},{\"fed\":\"ihg\"}]" },
{ "jkl", true },
{ "pqr", 1 },
{"abc", "[{\"def\":\"ghi\"},{\"fed\":\"ihg\"}]"},
{"jkl", true},
{"pqr", 1},
}).collect(Collectors.toMap(data -> (String) data[0], data -> data[1]));
assertEquals(expected, Jsons.flatten(json));
}

@Test
void testFlatten__withArraysApplyFlatten() {
final JsonNode json = Jsons
.deserialize("{ \"abc\": [{ \"def\": \"ghi\" }, { \"fed\": \"ihg\" }], \"jkl\": true, \"pqr\": 1 }");
Map<String, Object> expected = Stream.of(new Object[][] {
{ "abc.[0].def", "ghi" },
{ "abc.[1].fed", "ihg" },
{ "jkl", true },
{ "pqr", 1 },
{"abc.[0].def", "ghi"},
{"abc.[1].fed", "ihg"},
{"jkl", true},
{"pqr", 1},
}).collect(Collectors.toMap(data -> (String) data[0], data -> data[1]));
assertEquals(expected, Jsons.flatten(json, true));
}
Expand All @@ -323,10 +320,10 @@ void testFlatten__withArraysApplyFlattenNested() {
.deserialize(
"{ \"abc\": [{ \"def\": {\"ghi\": [\"xyz\"] }}, { \"fed\": \"ihg\" }], \"jkl\": true, \"pqr\": 1 }");
Map<String, Object> expected = Stream.of(new Object[][] {
{ "abc.[0].def.ghi.[0]", "xyz" },
{ "abc.[1].fed", "ihg" },
{ "jkl", true },
{ "pqr", 1 },
{"abc.[0].def.ghi.[0]", "xyz"},
{"abc.[1].fed", "ihg"},
{"jkl", true},
{"pqr", 1},
}).collect(Collectors.toMap(data -> (String) data[0], data -> data[1]));
assertEquals(expected, Jsons.flatten(json, true));
}
Expand All @@ -342,8 +339,7 @@ private static class ToClass {
@JsonProperty("numLong")
long numLong;

public ToClass() {
}
public ToClass() {}

public ToClass(final String str, final Integer num, final long numLong) {
this.str = str;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
/* * Copyright (c) 2022 Airbyte, Inc., all rights reserved. */
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.integrations.destination.postgres;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode ;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.airbyte.commons.json.Jsons;
import io.airbyte.db.jdbc.JdbcUtils;
import io.airbyte.integrations.base.Destination;
import io.airbyte.integrations.base.IntegrationRunner;
import io.airbyte.integrations.base.spec_modification.SpecModifyingDestination;
import io.airbyte.integrations.destination.postgres.PostgresDestination;
import io.airbyte.protocol.models.ConnectorSpecification;
import java.net.URI;
import java.net.URISyntaxException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BitDotIoDestination extends SpecModifyingDestination implements Destination {

private static final Logger LOGGER = LoggerFactory.getLogger(BitDotIoDestination.class);

public BitDotIoDestination() {
super(new PostgresDestination());
}
Expand All @@ -32,7 +33,7 @@ public ConnectorSpecification modifySpec(final ConnectorSpecification originalSp
String json = "[ \"database\", \"username\", \"password\"] ";

ObjectMapper objectMapper = new ObjectMapper();

JsonNode jsonNode;
try {
jsonNode = objectMapper.readTree(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,57 @@
import io.airbyte.integrations.base.JavaBaseConstants;
import io.airbyte.integrations.destination.ExtendedNameTransformer;
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.jooq.DSLContext;
import org.jooq.SQLDialect;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BitDotIoDestinationAcceptanceTest extends DestinationAcceptanceTest {

public class BitDotIoConfig {
private String username = "";
private String database = "";
private String password = "";
public String getUsername() {
return username;
}
public String getDatabase() {
return database;
}
public String getPassword() {
return password;
}
public BitDotIoConfig(String username, String database, String password)
{

private String username = "";
private String database = "";
private String password = "";

public String getUsername() {
return username;
}

public String getDatabase() {
return database;
}

public String getPassword() {
return password;
}

public BitDotIoConfig(String username, String database, String password) {
this.username = username;
this.database = database;
this.password = password;
}

public String getJdbcUrl() {
String jdbcUrl = "";
try {
jdbcUrl = "jdbc:postgresql://db.bit.io:5432" + "/" + URLEncoder.encode(database, "UTF-8") + "?sslmode=require";
} catch (UnsupportedEncodingException e) {
// Should never happen
e.printStackTrace();
}
return jdbcUrl;
String jdbcUrl = "";
try {
jdbcUrl = "jdbc:postgresql://db.bit.io:5432" + "/" + URLEncoder.encode(database, "UTF-8") + "?sslmode=require";
} catch (UnsupportedEncodingException e) {
// Should never happen
e.printStackTrace();
}
return jdbcUrl;
}
}

}

private static final Logger LOGGER = LoggerFactory.getLogger(BitDotIoDestinationAcceptanceTest.class);
private BitDotIoConfig cfg;
Expand All @@ -88,8 +91,8 @@ protected JsonNode getConfig() {
.put(JdbcUtils.USERNAME_KEY, cfg.getUsername())
.put(JdbcUtils.PASSWORD_KEY, cfg.getPassword())
.put(JdbcUtils.DATABASE_KEY, cfg.getDatabase())
.put(JdbcUtils.SSL_KEY, true )
.put("sslmode", "require" )
.put(JdbcUtils.SSL_KEY, true)
.put("sslmode", "require")
.put("ssl_mode", ImmutableMap.builder().put("mode", "require").build())
.build());
}
Expand All @@ -104,7 +107,7 @@ protected JsonNode getFailCheckConfig() {
.put(JdbcUtils.PASSWORD_KEY, "wrong password")
.put(JdbcUtils.DATABASE_KEY, cfg.getDatabase())
.put(JdbcUtils.SSL_KEY, true)
.put("sslmode", "require" )
.put("sslmode", "require")
.put("ssl_mode", ImmutableMap.builder().put("mode", "require").build())
.build());
}
Expand Down Expand Up @@ -173,6 +176,7 @@ private List<JsonNode> retrieveRecordsFromTable(final String tableName, final St
.collect(Collectors.toList()));
}
}

@Override
protected void setup(final TestDestinationEnv testEnv) throws Exception {
if (!Files.exists(CREDENTIALS_PATH)) {
Expand All @@ -187,8 +191,9 @@ protected void setup(final TestDestinationEnv testEnv) throws Exception {
final String database = credentialsJson.get(CONFIG_BITIO_DATABASE).asText();
final String password = credentialsJson.get(CONFIG_BITIO_CONNECT_PASSWORD).asText();

this.cfg = new BitDotIoConfig(username, database, password) ;
this.cfg = new BitDotIoConfig(username, database, password);
}

@Override
protected void tearDown(final TestDestinationEnv testEnv) {
try (final DSLContext dslContext = DSLContextFactory.create(
Expand All @@ -200,29 +205,32 @@ protected void tearDown(final TestDestinationEnv testEnv) {

Database db = new Database(dslContext);
List<JsonNode> tables = db.query(
ctx -> ctx
.fetch( "SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema not IN ('pg_catalog', 'information_schema');")
.stream()
.map(r -> r.formatJSON(JdbcUtils.getDefaultJSONFormat()))
.map(Jsons::deserialize)
.collect(Collectors.toList()));
for (JsonNode node : tables) {
db.query(ctx -> ctx.fetch(String.format("DROP TABLE IF EXISTS %s CASCADE", node.get("table_name"))));
}
ctx -> ctx
.fetch(
"SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema not IN ('pg_catalog', 'information_schema');")
.stream()
.map(r -> r.formatJSON(JdbcUtils.getDefaultJSONFormat()))
.map(Jsons::deserialize)
.collect(Collectors.toList()));
for (JsonNode node : tables) {
db.query(ctx -> ctx.fetch(String.format("DROP TABLE IF EXISTS %s CASCADE", node.get("table_name"))));
}
List<JsonNode> schemas = db.query(
ctx -> ctx
.fetch( "SELECT DISTINCT table_schema FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema not IN ('public', 'pg_catalog', 'information_schema');")
.stream()
.map(r -> r.formatJSON(JdbcUtils.getDefaultJSONFormat()))
.map(Jsons::deserialize)
.collect(Collectors.toList()));
for (JsonNode node : schemas) {
db.query(ctx -> ctx.fetch(String.format("DROP SCHEMA IF EXISTS %s CASCADE", node.get("table_schema"))));
}
ctx -> ctx
.fetch(
"SELECT DISTINCT table_schema FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema not IN ('public', 'pg_catalog', 'information_schema');")
.stream()
.map(r -> r.formatJSON(JdbcUtils.getDefaultJSONFormat()))
.map(Jsons::deserialize)
.collect(Collectors.toList()));
for (JsonNode node : schemas) {
db.query(ctx -> ctx.fetch(String.format("DROP SCHEMA IF EXISTS %s CASCADE", node.get("table_schema"))));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LOGGER.info("Finished acceptance test for bit.io");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Postgres Destination Spec",
"type": "object",
"required": [
"database",
"username",
"password"
],
"required": ["database", "username", "password"],
"additionalProperties": true,
"properties": {
"database": {
Expand All @@ -25,9 +21,7 @@
"title": "Default Schema",
"description": "The default schema tables are written to if the source does not specify a namespace. The usual value for this field is \"public\".",
"type": "string",
"examples": [
"public"
],
"examples": ["public"],
"default": "public",
"order": 3
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ protected String getWrappedColumnNames(final JdbcDatabase database,
final Connection connection,
final List<String> columnNames,
final String schemaName,
final String tableName) throws SQLException {
final String tableName)
throws SQLException {
return sourceOperations.enquoteIdentifierList(connection, columnNames);
}

Expand Down
Loading

0 comments on commit 491f5ff

Please sign in to comment.