Skip to content

PLUGIN-1883: SnowFlake Plugin - Fetch schema using Named Table #48

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

Merged
merged 1 commit into from
May 15, 2025

Conversation

sgarg-CS
Copy link
Contributor

@sgarg-CS sgarg-CS commented Apr 21, 2025

PLUGIN-1883

Key changes :-

  • Added Import Query Type radio button plugin property with the following options to choose from
    • Native Query
    • Named Table
  • Added Table Name property in Snowflake Source plugin properties
  • Modified schema retrieval using table name and importQuery

When Import Query Type is Native Query
image

When Import Query Type is Named Table
image

@sgarg-CS sgarg-CS marked this pull request as ready for review April 21, 2025 08:45
@sgarg-CS sgarg-CS added the build build label Apr 21, 2025
@@ -23,7 +23,6 @@
import io.cdap.plugin.snowflake.common.BaseSnowflakeConfig;
import io.cdap.plugin.snowflake.common.client.SnowflakeAccessor;
import io.cdap.plugin.snowflake.common.util.SchemaHelper;

Copy link
Member

Choose a reason for hiding this comment

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

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted f1e33c0

import io.cdap.cdap.api.annotation.Description;
import io.cdap.cdap.api.annotation.Macro;
import io.cdap.cdap.api.annotation.Name;
import io.cdap.cdap.etl.api.FailureCollector;
import io.cdap.plugin.snowflake.common.BaseSnowflakeConfig;

Copy link
Member

Choose a reason for hiding this comment

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

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted f1e33c0

Comment on lines 132 to 140
List<Schema.Field> fields = result.stream()
.map(fieldDescriptor -> Schema.Field.of(fieldDescriptor.getName(), getSchema(fieldDescriptor)))
.collect(Collectors.toList());
return Schema.recordOf("data", fields);
} catch (SQLException e) {
throw new SchemaParseException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
Copy link
Member

Choose a reason for hiding this comment

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

any exception should be returned as SchemaParseException here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done bf54c00

@@ -95,5 +129,11 @@ public void validate(FailureCollector collector) {
collector.addFailure("Maximum Slit Size cannot be a negative number.", null)
.withConfigProperty(PROPERTY_MAX_SPLIT_SIZE);
}

if (Strings.isNullOrEmpty(importQuery) && Strings.isNullOrEmpty(tableName)) {
Copy link
Member

Choose a reason for hiding this comment

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

also add validation for importQueryType

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added bf54c00

String importQuery = config.getImportQuery();
if (Strings.isNullOrEmpty(importQuery)) {
String tableName = config.getTableName();
importQuery = String.format("SELECT * FROM %s", tableName);
Copy link
Member

Choose a reason for hiding this comment

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

ideally we should only import columns present in the schema, why SELECT *?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For tableName, I think SELECT * should be fine. There is an importQuery option, if the user wishes to specify the individual columns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored the code. b7ca095 PTAL.

Comment on lines 103 to 104
"For more details, see %s.", STAGE_PATH, e.getErrorCode(), e.getSQLState(),
DocumentUrlUtil.getSupportedDocumentUrl());
Copy link
Member

Choose a reason for hiding this comment

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

bad indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 482c537

return type;
}
}

Copy link
Member

Choose a reason for hiding this comment

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

remove empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed bf54c00

* @return list of field descriptors
* @throws SQLException If an error occurs while retrieving metadata from the database
*/
public List<SnowflakeFieldDescriptor> describeTable(String schemaName, String tableName) throws SQLException {
Copy link
Member

Choose a reason for hiding this comment

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

please keep the method name to reflect what exactly is being done, something like getFieldDescriptors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed dad7ba9

* @return list of field descriptors
* @throws SQLException If an error occurs while retrieving metadata from the database
*/
public List<SnowflakeFieldDescriptor> getFieldDescriptors(String schemaName, String tableName) throws SQLException {
Copy link
Member

Choose a reason for hiding this comment

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

can it still throw SQLException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, removed it. 30ba2aa

.map(fieldDescriptor -> Schema.Field.of(fieldDescriptor.getName(), getSchema(fieldDescriptor)))
.collect(Collectors.toList());
return Schema.recordOf("data", fields);
} catch (SQLException e) {
Copy link
Member

Choose a reason for hiding this comment

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

from where is this thrown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This exception is not thrown. Redundant catch block. Removed it. 30ba2aa

@sgarg-CS sgarg-CS force-pushed the feature/PLUGIN-1883 branch from 30ba2aa to 9d8bc2c Compare May 15, 2025 11:51
@sgarg-CS sgarg-CS merged commit afb8619 into data-integrations:develop May 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants