[PLUGIN-1883] SnowFlake Plugin - Fetch schema using Named Table#48
Conversation
| import io.cdap.plugin.snowflake.common.BaseSnowflakeConfig; | ||
| import io.cdap.plugin.snowflake.common.client.SnowflakeAccessor; | ||
| import io.cdap.plugin.snowflake.common.util.SchemaHelper; | ||
|
|
| import io.cdap.cdap.api.annotation.Name; | ||
| import io.cdap.cdap.etl.api.FailureCollector; | ||
| import io.cdap.plugin.snowflake.common.BaseSnowflakeConfig; | ||
|
|
| 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.
any exception should be returned as SchemaParseException here
| .withConfigProperty(PROPERTY_MAX_SPLIT_SIZE); | ||
| } | ||
|
|
||
| if (Strings.isNullOrEmpty(importQuery) && Strings.isNullOrEmpty(tableName)) { |
There was a problem hiding this comment.
also add validation for importQueryType
| 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.
ideally we should only import columns present in the schema, why SELECT *?
There was a problem hiding this comment.
For tableName, I think SELECT * should be fine. There is an importQuery option, if the user wishes to specify the individual columns.
| "For more details, see %s.", STAGE_PATH, e.getErrorCode(), e.getSQLState(), | ||
| DocumentUrlUtil.getSupportedDocumentUrl()); |
| return type; | ||
| } | ||
| } | ||
|
|
| * @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.
please keep the method name to reflect what exactly is being done, something like getFieldDescriptors
| * @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.
can it still throw SQLException?
| .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.
from where is this thrown?
There was a problem hiding this comment.
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 QueryWhen Import Query Type is

Named Table