-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: develop
Are you sure you want to change the base?
Conversation
97d8e50
to
2ae73ac
Compare
To do : Internal Review Pending. |
cloudsql-postgresql-plugin/pom.xml
Outdated
@@ -102,6 +102,12 @@ | |||
<version>42.3.1</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.code.gson</groupId> |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Sout
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conn -> connection
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connect -> connection
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra spacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 !
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
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.
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.
There was a problem hiding this comment.
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; | |||
|
There was a problem hiding this comment.
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(----------);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change done
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