Don't fail on invalid views in InformationSchema (#10960)

* Don't fail on invalid views in InformationSchema

* Fix test
This commit is contained in:
Jonathan Wei 2021-03-09 16:19:59 -08:00 committed by GitHub
parent 7f96ca8f5e
commit 9c083783c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -46,6 +46,7 @@ import org.apache.calcite.schema.TableMacro;
import org.apache.calcite.schema.impl.AbstractSchema;
import org.apache.calcite.schema.impl.AbstractTable;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.druid.java.util.emitter.EmittingLogger;
import org.apache.druid.segment.column.RowSignature;
import org.apache.druid.segment.column.ValueType;
import org.apache.druid.server.security.AuthenticationResult;
@ -64,6 +65,8 @@ import java.util.Set;
public class InformationSchema extends AbstractSchema
{
private static final EmittingLogger log = new EmittingLogger(InformationSchema.class);
private static final String CATALOG_NAME = "druid";
private static final String SCHEMATA_TABLE = "SCHEMATA";
private static final String TABLES_TABLE = "TABLES";
@ -357,6 +360,7 @@ public class InformationSchema extends AbstractSchema
return null;
}
try {
return generateColumnMetadata(
schemaName,
functionName,
@ -364,6 +368,11 @@ public class InformationSchema extends AbstractSchema
typeFactory
);
}
catch (Exception e) {
log.error(e, "Encountered exception while handling view[%s].", functionName);
return null;
}
}
}
)
),

View File

@ -830,6 +830,12 @@ public class BaseCalciteQueryTest extends CalciteTestBase
"restrictedView",
"SELECT __time, dim1, dim2, m1 FROM druid.forbiddenDatasource WHERE dim2 = 'a'"
);
viewManager.createView(
plannerFactory,
"invalidView",
"SELECT __time, dim1, dim2, m1 FROM druid.invalidDatasource WHERE dim2 = 'a'"
);
return sqlLifecycleFactory;
}

View File

@ -889,6 +889,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
.add(new Object[]{"view", "bview", "VIEW", "NO", "NO"})
.add(new Object[]{"view", "cview", "VIEW", "NO", "NO"})
.add(new Object[]{"view", "dview", "VIEW", "NO", "NO"})
.add(new Object[]{"view", "invalidView", "VIEW", "NO", "NO"})
.add(new Object[]{"view", "restrictedView", "VIEW", "NO", "NO"})
.build()
);
@ -924,6 +925,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
.add(new Object[]{"view", "cview", "VIEW", "NO", "NO"})
.add(new Object[]{"view", "dview", "VIEW", "NO", "NO"})
.add(new Object[]{"view", "forbiddenView", "VIEW", "NO", "NO"})
.add(new Object[]{"view", "invalidView", "VIEW", "NO", "NO"})
.add(new Object[]{"view", "restrictedView", "VIEW", "NO", "NO"})
.build()
);