Conversation
97d8e50 to
2ae73ac
Compare
|
To do : Internal Review Pending. |
cloudsql-postgresql-plugin/pom.xml
Outdated
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.code.gson</groupId> |
There was a problem hiding this comment.
Why do we need this ?
There was a problem hiding this comment.
This is basically used to convert java objects into json representation and vice versa so that's why we are using this.
There was a problem hiding this comment.
Its already present in google-http-client dependency which is added in cdap-e2e-test repo. Use import com.google.gson.Gson and try if you are able to resolve it without adding a extra dependency for Gson.
| zeroValue=0 | ||
| splitByColumn=ID | ||
| importQuery = where $CONDITIONS | ||
| connectionName=CONNECTION_NAME |
There was a problem hiding this comment.
make it CLOUDSQL_POSTGRESQL_CONNECTION_NAME
| import java.text.ParseException; | ||
|
|
||
| /** | ||
| * CLOUDSQLPOSTGRESQL Plugin related step design. |
There was a problem hiding this comment.
CloudSQL PostgreSQL Step design sounds better.
| */ | ||
| public class CloudSqlPostgreSql implements CdfHelper { | ||
|
|
||
| @Then("Click on preview data for CloudSQLPostgreSQL sink") |
There was a problem hiding this comment.
Why do we need to write a step here, we can use it from framework.
| @CucumberOptions( | ||
| features = {"src/e2e-test/features"}, | ||
| glue = {"io.cdap.plugin.cloudsqlpostgresql.stepsdesign", "stepsdesign", "io.cdap.plugin.common.stepsdesign"}, | ||
| tags = {"@Cloudsqlpostgresql_Source and not @PLUGIN-1526"}, |
There was a problem hiding this comment.
We don't have to write the name of the tag same as plugins name. It looks complex. Can we Just use Regression as a tag.
| @CucumberOptions( | ||
| features = {"src/e2e-test/features"}, | ||
| glue = {"io.cdap.plugin.cloudsqlpostgresql.stepsdesign", "stepsdesign", "io.cdap.plugin.common.stepsdesign"}, | ||
| tags = {"@Cloudsqlpostgresql_Sink and not @PLUGIN-1629 and not @PLUGIN-1526"}, |
There was a problem hiding this comment.
Same comment here lets make it Regression
| String password = System.getenv("CLOUDSQL_POSTGRESQL_PASSWORD"); | ||
|
|
||
| String jdbcUrl = String.format( | ||
| "jdbc:postgresql://google/%s?cloudSqlInstance=%s&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=%s&password=%s", |
There was a problem hiding this comment.
Don't hardcode this URL here, fetch it from Plugin Parameter.properties
| "jdbc:postgresql://google/%s?cloudSqlInstance=%s&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=%s&password=%s", | ||
| database,instanceConnectionName, username, password); | ||
| Connection conn = DriverManager.getConnection(jdbcUrl); | ||
| System.out.println("Connected to the database successfully"); |
There was a problem hiding this comment.
Remove Sout
| database,instanceConnectionName, username, password); | ||
| Connection conn = DriverManager.getConnection(jdbcUrl); | ||
| System.out.println("Connected to the database successfully"); | ||
| return conn; |
There was a problem hiding this comment.
conn -> connection
| } | ||
|
|
||
| /** | ||
| * Extracts entire data from source and target tables. |
There was a problem hiding this comment.
Extracts Result set of source and target table.
| throws SQLException, ClassNotFoundException { | ||
| String getSourceQuery = "SELECT * FROM " + schema + "." + sourceTable; | ||
| String getTargetQuery = "SELECT * FROM " + schema + "." + targetTable; | ||
| try (Connection connect = getCloudSqlConnection()) { |
There was a problem hiding this comment.
connect -> connection
| while (rsSource.next() && rsTarget.next()) { | ||
| int currentColumnCount = 1; | ||
| while (currentColumnCount <= columnCountSource) { | ||
| String columnTypeName = mdSource.getColumnTypeName(currentColumnCount); |
There was a problem hiding this comment.
Is this logic of comparing result set copied from PostgreSQL ? How do we even know we just have to cover timestamp in a separate case and rest we can compare as a string.
| throws SQLException, ClassNotFoundException, IOException, InterruptedException { | ||
| getBigQueryTableData(targetTable, bigQueryRows); | ||
| for (Object rows : bigQueryRows) { | ||
| JsonObject json = new Gson().fromJson(String.valueOf(rows), JsonObject.class); |
There was a problem hiding this comment.
You have already used Lists as global variables. Create a global Gson object and re use it in all the methods.
| /** | ||
| * Retrieves the data from a specified BigQuery table and populates it into the provided list of objects. | ||
| * | ||
| * @param table The name of the BigQuery table to fetch data from. |
There was a problem hiding this comment.
Remove the extra spacing.
There was a problem hiding this comment.
I don't see any commit. push the commit and add the link here
| BigDecimal targetDecimal = bigQueryData.get(jsonObjectIdx).get(columnName).getAsBigDecimal(); | ||
| int desiredScale = 2; // Set the desired scale (number of decimal places) | ||
| BigDecimal adjustedSourceValue = sourceDecimal.setScale(desiredScale, RoundingMode.HALF_UP); | ||
| BigDecimal adjustedTargetValue = targetDecimal.setScale(desiredScale, RoundingMode.HALF_UP); |
There was a problem hiding this comment.
I see we are setting scale here, was there any discrepancy in the original data which was needed to be handled.
There was a problem hiding this comment.
We need to match precision scale of both side to avoid errors cause due to auto round off when precision mismatch
example -> 2.126 (3 decimal precision) will be converted to 2.13 (2 decimal precision) (round off)
👍
| break; | ||
|
|
||
| case Types.TIMESTAMP: | ||
| break; |
There was a problem hiding this comment.
As discussed we need to add the logic here we are not going to simply add break here.
| } | ||
| } | ||
|
|
||
| private static boolean getTimeValidation(ResultSet rsSource, String bqDateString, String columnName, String |
There was a problem hiding this comment.
Is this method getting used somewhere now ?
There was a problem hiding this comment.
you are using this code Timestamp sourceTS = rsSource.getTimestamp(columnName); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); Date parsedDate = dateFormat.parse(bigQueryData.get(jsonObjectIdx).get(columnName).getAsString()); Timestamp targetTs = new Timestamp(parsedDate.getTime()); Assert.assertEquals(sourceTS, targetTs);
To comapre time stamp data. Then what is this method used for ?
There was a problem hiding this comment.
We are using getTimeValidation for Time with and without zone data not for Timestamp
…ql-postgreSql # Conflicts: # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/sink/DesignTime.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/sink/DesignTimeWithMacros.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/sink/DesignTimeWithValidation.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/sink/RunTime.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/sink/RunTimeMacro.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/source/DesignTime.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/source/DesignTimeWithMacro.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/source/DesignTimeWithValidation.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/source/RunTime.feature # cloudsql-postgresql-plugin/src/e2e-test/feature/cloudsql-postgresql/source/RunTimeMacro.feature # cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/BQValidation.java # cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/CloudSqlPostgreSqlClient.java # cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/runners/sinkrunner/TestRunner.java # cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/runners/sourcerunner/TestRunner.java # cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/stepsdesign/CloudSqlPostgreSql.java # cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/common/stepsdesign/TestSetUpHooks.java # cloudsql-postgresql-plugin/src/e2e-test/resources/pluginParameters.properties # cloudsql-postgresql-plugin/src/e2e-test/resources/testdata/BigQuery/BigQueryInsertDataQuery.txt
351fee6 to
8cdbadd
Compare
| String instanceConnectionName = System.getenv("CLOUDSQL_POSTGRESQL_CONNECTION_NAME"); | ||
| String username = System.getenv("CLOUDSQL_POSTGRESQL_USERNAME"); | ||
| String password = System.getenv("CLOUDSQL_POSTGRESQL_PASSWORD"); | ||
| String jdbcUrl = String.format(PluginPropertyUtils.pluginProp("URL"), database, instanceConnectionName, username, password); |
There was a problem hiding this comment.
Did you tested the code after adding this URL from plugin properties if its working fine.
There was a problem hiding this comment.
yes this is working fine.
| static List<JsonObject> BigQueryResponse = new ArrayList<>(); | ||
| static List<Object> bigQueryRows = new ArrayList<>(); | ||
| static JsonObject json; | ||
|
|
There was a problem hiding this comment.
Didn't asked to create a JsonObject global . I asked to create this here.
Gson gson = new Gson()
JsonObject json = gson.fromJson(----------);
285d30e to
194d85d
Compare
|
@bharatgulati Changes look good all the comments have been addressed. Raise an external PR after dry running the data validation logic once. |
@itsmekumari @AnkitCLI