-
Notifications
You must be signed in to change notification settings - Fork 9
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
PLUGIN-1883: SnowFlake Plugin - Fetch schema using Named Table #48
Conversation
@@ -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; | |||
|
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 this change?
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.
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; | ||
|
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 this change?
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.
Reverted f1e33c0
src/main/java/io/cdap/plugin/snowflake/source/batch/ImportQueryType.java
Outdated
Show resolved
Hide resolved
src/main/java/io/cdap/plugin/snowflake/source/batch/SnowflakeBatchSourceConfig.java
Show resolved
Hide resolved
src/main/java/io/cdap/plugin/snowflake/source/batch/SnowflakeBatchSourceConfig.java
Outdated
Show resolved
Hide resolved
src/main/java/io/cdap/plugin/snowflake/source/batch/SnowflakeBatchSourceConfig.java
Outdated
Show resolved
Hide resolved
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); | ||
} |
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.
any exception should be returned as SchemaParseException
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 bf54c00
src/main/java/io/cdap/plugin/snowflake/common/util/SchemaHelper.java
Outdated
Show resolved
Hide resolved
@@ -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)) { |
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.
also add validation for importQueryType
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.
Added bf54c00
String importQuery = config.getImportQuery(); | ||
if (Strings.isNullOrEmpty(importQuery)) { | ||
String tableName = config.getTableName(); | ||
importQuery = String.format("SELECT * FROM %s", 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.
ideally we should only import columns present in the schema, why SELECT *
?
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 tableName
, I think SELECT *
should be fine. There is an importQuery
option, if the user wishes to specify the individual columns.
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.
Refactored the code. b7ca095 PTAL.
"For more details, see %s.", STAGE_PATH, e.getErrorCode(), e.getSQLState(), | ||
DocumentUrlUtil.getSupportedDocumentUrl()); |
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.
bad indentation
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.
Fixed 482c537
return type; | ||
} | ||
} | ||
|
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 empty line
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 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 { |
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.
please keep the method name to reflect what exactly is being done, something like getFieldDescriptors
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.
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 { |
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.
can it still throw SQLException
?
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, removed it. 30ba2aa
.map(fieldDescriptor -> Schema.Field.of(fieldDescriptor.getName(), getSchema(fieldDescriptor))) | ||
.collect(Collectors.toList()); | ||
return Schema.recordOf("data", fields); | ||
} catch (SQLException e) { |
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.
from where is this thrown?
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 exception is not thrown. Redundant catch block. Removed it. 30ba2aa
30ba2aa
to
9d8bc2c
Compare
PLUGIN-1883
Key changes :-
When Import Query Type is

Native Query
When Import Query Type is

Named Table