-
Notifications
You must be signed in to change notification settings - Fork 34
Patch/abhi tablename : Adding import query type property and modify tableName property for redshift and postgres plugin #607
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
base: develop
Are you sure you want to change the base?
Conversation
} | ||
|
||
/** | ||
* Helper method for type mapping when fetching schema by table 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.
this is not proper javadoc format, use that one
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.
changed and used javadoc format.
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.
changed
/** | ||
* Override: Fetches schema fields for a specific table using database metadata. | ||
*/ | ||
@Override |
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.
It is there in parent class, you can use that one, instead you can call getSchema method of this class inside
public void configurePipeline(PipelineConfigurer pipelineConfigurer) { | ||
FailureCollector collector = pipelineConfigurer.getStageConfigurer().getFailureCollector(); | ||
if (!sourceConfig.containsMacro("tableName") && !sourceConfig.containsMacro("importQuery")) { | ||
if ((sourceConfig.getTableName() == null || sourceConfig.getTableName().isEmpty()) |
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.
Use Strings method for null empty check
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.
changed
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
if ((sourceConfig.getTableName() == null || sourceConfig.getTableName().isEmpty()) | ||
&& (sourceConfig.getImportQuery() == null || sourceConfig.getImportQuery().isEmpty())) { | ||
collector.addFailure( | ||
"Either 'tableName' or 'importQuery' must be specified for the PostgreSQL source.", |
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 DB name from 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.
removed
@@ -88,6 +107,11 @@ protected LineageRecorder getLineageRecorder(BatchSourceContext context) { | |||
return new LineageRecorder(context, assetBuilder.build()); | |||
} | |||
|
|||
public DatabaseMetaData getDatabaseMetadata(Connection connection) throws SQLException { | |||
return (DatabaseMetaData) connection.getMetaData().getColumns(null, | |||
null, redshiftSourceConfig.getTableName(), null); |
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.
schema is not handled here, if customer is passing "schema.tablename", it will not work
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.
for now this method is not used so no need to handle we can remove this method .
{ | ||
"name": "ImportQuery", | ||
"condition": { | ||
"expression": "importQueryType == 'importQuery'" |
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.
use condition importQueryType != 'tableName'
, it will be backward compatible then
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
@@ -251,6 +275,30 @@ | |||
"name": "port" | |||
} | |||
] | |||
}, |
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.
no need to add filters as it is hidden
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.
keeping it so that if further we have to make changes for this we can just changed the hidden property.
but if not required , will removed..
/** | ||
* Resolves the actual table name from the database in a case-insensitive way. | ||
*/ | ||
private String resolveTableName(DatabaseMetaData dbMetaData, String schema, String userTableName) |
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 this method, as it can create issues in case sensitive DBs
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.
removed and back to previous method .
@@ -163,7 +164,14 @@ public Schema getSchema() throws SQLException { | |||
try (Connection connection = getConnection()) { | |||
executeInitQueries(connection, sourceConfig.getInitQueries()); | |||
String query = sourceConfig.getImportQuery(); | |||
return loadSchemaFromDB(connection, query); | |||
if (query != null && !query.isEmpty()) { |
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.
Add Strings class method for null check
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.
changed.
@@ -174,9 +182,14 @@ private Schema loadSchemaFromDB(Connection connection, String query) throws SQLE | |||
query = removeConditionsClause(query); | |||
} | |||
ResultSet resultSet = statement.executeQuery(query); | |||
DatabaseMetaData databaseMetaData = getDatabaseMetadata(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.
you are not using it, remove it
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.
removed.
if (!Strings.isNullOrEmpty(importQuery)) { | ||
return loadSchemaFromDB(connection, importQuery); | ||
} else { | ||
String query = String.format("SELECT * FROM %s LIMIT 1", tableName); |
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 have fetch schema from database metadata in case of tableName, this should not behave like this
@@ -73,7 +72,7 @@ public Schema getSchema(ResultSetMetaData metadata, int index) throws SQLExcepti | |||
return Schema.of(Schema.Type.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.
remove
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.
removed
if ((sourceConfig.getTableName() == null || sourceConfig.getTableName().isEmpty()) | ||
&& (sourceConfig.getImportQuery() == null || sourceConfig.getImportQuery().isEmpty())) { | ||
collector.addFailure( | ||
"Either 'tableName' or 'importQuery' must be specified for the PostgreSQL source.", |
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 db 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.
removed
Adding import query type property and modify tableName property for redshift and postgres plugin