@BeforeMethod(alwaysRun = true)
public void setup()
throws Exception
{
MetadataManager metadata = new MetadataManager(new FeaturesConfig().setExperimentalSyntaxEnabled(true), new TypeRegistry(), new SystemTablesMetadata());
metadata.addConnectorMetadata("tpch", "tpch", new TestingMetadata());
metadata.addConnectorMetadata("c2", "c2", new TestingMetadata());
metadata.addConnectorMetadata("c3", "c3", new TestingMetadata());
SchemaTableName table1 = new SchemaTableName("default", "t1");
metadata.createTable(SESSION, "tpch", new TableMetadata("tpch", new ConnectorTableMetadata(table1,
ImmutableList.<ColumnMetadata>of(
new ColumnMetadata("a", BIGINT, 0, false),
new ColumnMetadata("b", BIGINT, 1, false),
new ColumnMetadata("c", BIGINT, 2, false),
new ColumnMetadata("d", BIGINT, 3, false)))));
SchemaTableName table2 = new SchemaTableName("default", "t2");
metadata.createTable(SESSION, "tpch", new TableMetadata("tpch", new ConnectorTableMetadata(table2,
ImmutableList.<ColumnMetadata>of(
new ColumnMetadata("a", BIGINT, 0, false),
new ColumnMetadata("b", BIGINT, 1, false)))));
SchemaTableName table3 = new SchemaTableName("default", "t3");
metadata.createTable(SESSION, "tpch", new TableMetadata("tpch", new ConnectorTableMetadata(table3,
ImmutableList.<ColumnMetadata>of(
new ColumnMetadata("a", BIGINT, 0, false),
new ColumnMetadata("b", BIGINT, 1, false)))));
// table in different catalog
SchemaTableName table4 = new SchemaTableName("s2", "t4");
metadata.createTable(SESSION, "c2", new TableMetadata("tpch", new ConnectorTableMetadata(table4,
ImmutableList.<ColumnMetadata>of(
new ColumnMetadata("a", BIGINT, 0, false)))));
// valid view referencing table in same schema
String viewData1 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(
new ViewDefinition("select a from t1", "tpch", "default", ImmutableList.of(
new ViewColumn("a", BIGINT))));
metadata.createView(SESSION, new QualifiedTableName("tpch", "default", "v1"), viewData1, false);
// stale view (different column type)
String viewData2 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(
new ViewDefinition("select a from t1", "tpch", "default", ImmutableList.of(
new ViewColumn("a", VARCHAR))));
metadata.createView(SESSION, new QualifiedTableName("tpch", "default", "v2"), viewData2, false);
// view referencing table in different schema from itself and session
String viewData3 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(
new ViewDefinition("select a from t4", "c2", "s2", ImmutableList.of(
new ViewColumn("a", BIGINT))));
metadata.createView(SESSION, new QualifiedTableName("c3", "s3", "v3"), viewData3, false);
analyzer = new Analyzer(
Session.builder()
.setUser("user")
.setSource("test")