[
https://issues.apache.org/jira/browse/DRILL-4673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15371691#comment-15371691
]
ASF GitHub Bot commented on DRILL-4673:
---------------------------------------
Github user sudheeshkatkam commented on a diff in the pull request:
https://github.com/apache/drill/pull/541#discussion_r70342372
--- Diff:
exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
---
@@ -106,36 +106,43 @@ public PhysicalPlan getPlan(SqlNode sqlNode) throws
ValidationException, RelConv
}
}
- /** Handler for Drop View DDL command. */
- public static class DropView extends ViewHandler {
- public DropView(SqlHandlerConfig config) {
+ /** Handler for Drop View [If Exists] DDL command. */
+ public static class DropViewIfExists extends ViewHandler {
+ public DropViewIfExists(SqlHandlerConfig config) {
super(config);
}
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws
ValidationException, RelConversionException, IOException, ForemanSetupException
{
- SqlDropView dropView = unwrap(sqlNode, SqlDropView.class);
- final String viewToDrop = dropView.getName();
+ SqlDropViewIfExists dropView = unwrap(sqlNode,
SqlDropViewIfExists.class);
+ final String viewName = dropView.getName();
final AbstractSchema drillSchema =
SchemaUtilites.resolveToMutableDrillSchema(context.getNewDefaultSchema(),
dropView.getSchemaPath());
final String schemaPath = drillSchema.getFullSchemaName();
- final Table existingTable =
SqlHandlerUtil.getTableFromSchema(drillSchema, viewToDrop);
- if (existingTable != null && existingTable.getJdbcTableType() !=
Schema.TableType.VIEW) {
- throw UserException.validationError()
- .message("[%s] is not a VIEW in schema [%s]", viewToDrop,
schemaPath)
- .build(logger);
- } else if (existingTable == null) {
- throw UserException.validationError()
- .message("Unknown view [%s] in schema [%s].", viewToDrop,
schemaPath)
- .build(logger);
+ final Table viewToDrop =
SqlHandlerUtil.getTableFromSchema(drillSchema, viewName);
+ if (dropView.checkViewExistence()) {
+ if (viewToDrop == null || viewToDrop.getJdbcTableType() !=
Schema.TableType.VIEW){
--- End diff --
Same here. I am not sure a `null` check is sufficient.
> Implement "DROP TABLE IF EXISTS" for drill to prevent FAILED status on
> command return
> -------------------------------------------------------------------------------------
>
> Key: DRILL-4673
> URL: https://issues.apache.org/jira/browse/DRILL-4673
> Project: Apache Drill
> Issue Type: New Feature
> Components: Functions - Drill
> Reporter: Vitalii Diravka
> Assignee: Vitalii Diravka
> Priority: Minor
> Labels: drill
>
> Implement "DROP TABLE IF EXISTS" for drill to prevent FAILED status on
> command "DROP TABLE" return if table doesn't exist.
> The same for "DROP VIEW IF EXISTS"
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)