Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudSql PostgreSql e2e #12

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open

Conversation

Vipinofficial11
Copy link
Collaborator

@Vipinofficial11 Vipinofficial11 commented Jun 1, 2023

@Vipinofficial11 Vipinofficial11 changed the title Cloud sql postgre sql CLOUDSQL POSTGRESQL Jun 1, 2023
@Vipinofficial11 Vipinofficial11 changed the title CLOUDSQL POSTGRESQL CloudSql PostgreSql e2e Jun 1, 2023
@Vipinofficial11 Vipinofficial11 marked this pull request as ready for review June 1, 2023 18:27
@Vipinofficial11
Copy link
Collaborator Author

To do : Internal Review Pending.

@@ -102,6 +102,12 @@
<version>42.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically used to convert java objects into json representation and vice versa so that's why we are using this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it CLOUDSQL_POSTGRESQL_CONNECTION_NAME

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import java.text.ParseException;

/**
* CLOUDSQLPOSTGRESQL Plugin related step design.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CloudSQL PostgreSQL Step design sounds better.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

*/
public class CloudSqlPostgreSql implements CdfHelper {

@Then("Click on preview data for CloudSQLPostgreSQL sink")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to write a step here, we can use it from framework.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@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"},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change done.

@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"},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here lets make it Regression

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change done.

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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode this URL here, fetch it from Plugin Parameter.properties

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"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");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Sout

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

database,instanceConnectionName, username, password);
Connection conn = DriverManager.getConnection(jdbcUrl);
System.out.println("Connected to the database successfully");
return conn;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conn -> connection

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

/**
* Extracts entire data from source and target tables.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracts Result set of source and target table.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change done.

throws SQLException, ClassNotFoundException {
String getSourceQuery = "SELECT * FROM " + schema + "." + sourceTable;
String getTargetQuery = "SELECT * FROM " + schema + "." + targetTable;
try (Connection connect = getCloudSqlConnection()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connect -> connection

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

while (rsSource.next() && rsTarget.next()) {
int currentColumnCount = 1;
while (currentColumnCount <= columnCountSource) {
String columnTypeName = mdSource.getColumnTypeName(currentColumnCount);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Collaborator Author

@Vipinofficial11 Vipinofficial11 Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have already used Lists as global variables. Create a global Gson object and re use it in all the methods.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change done

/**
* 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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra spacing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any commit. push the commit and add the link here

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we are setting scale here, was there any discrepancy in the original data which was needed to be handled.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed we need to add the logic here we are not going to simply add break here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

private static boolean getTimeValidation(ResultSet rsSource, String bqDateString, String columnName, String
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method getting used somewhere now ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we are using this !

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you tested the code after adding this URL from plugin properties if its working fine.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this is working fine.

@@ -40,51 +42,52 @@
public class BQValidation {
static List<JsonObject> BigQueryResponse = new ArrayList<>();
static List<Object> bigQueryRows = new ArrayList<>();
static JsonObject json;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't asked to create a JsonObject global . I asked to create this here.
Gson gson = new Gson()
JsonObject json = gson.fromJson(----------);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change done

@Vipinofficial11
Copy link
Collaborator Author

@bharatgulati Changes look good all the comments have been addressed. Raise an external PR after dry running the data validation logic once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants