Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
1.13.0
-
None
-
None
-
None
Description
Create a view views and look at the list of columns within the view. You'll see that they are often wrong in name, type and mode.
Consider a very simple CSV file with headers:
custId,name,balance,status 123,Fred,456.78 125,Betty,98.76,VIP 128,Barney,1.23,PAST DUE,30
Define the simplest possible view:
CREATE VIEW myView2 AS SELECT * FROM `csvh/cust.csvh`;
Then look at the view file:
{ "name" : "myView2", "sql" : "SELECT *\nFROM `csvh/cust.csvh`", "fields" : [ { "name" : "**", "type" : "DYNAMIC_STAR", "isNullable" : true } ], "workspaceSchemaPath" : [ "local", "data" ] }
It is clear that the view simply captured the plan-time list of the new double-star for the wildcard. Since this is not a true type, it should not have an `isNullable` attribute.
OK, we have to spell out the columns:
CREATE VIEW myView3 AS SELECT custId FROM `csvh/cust.csvh`;
Let's look at the view file:
{ "name" : "myView3", "sql" : "SELECT `custId`\nFROM `csvh/cust.csvh`", "fields" : [ { "name" : "custId", "type" : "ANY", "isNullable" : true } ], "workspaceSchemaPath" : [ "local", "data" ] }
The name is correct. The type is `ANY`, which is wrong. Since this is a CSV file, the column type is `VARCHAR`. Further, because this is a CSV file which headers, the mode is REQUIRED, but is listed as nullable. To verify:
SELECT sqlTypeOf(custId), modeOf(custId) FROM myView3 LIMIT 1; +--------------------+-----------+ | EXPR$0 | EXPR$1 | +--------------------+-----------+ | CHARACTER VARYING | NOT NULL | +--------------------+-----------+
Now, let's try a CSV file without headers:
123,Fred,456.78 125,Betty,98.76,VIP
CREATE VIEW myView4 AS SELECT columns FROM `csv/cust.csv`; SELECT * FROM myView4; +--------------------------------+ | columns | +--------------------------------+ | ["123","Fred","456.78"] | | ["125","Betty","98.76","VIP"] | +--------------------------------+
Let's look at the view file:
{ "name" : "myView4", "sql" : "SELECT `columns`\nFROM `csv/cust.csv`", "fields" : [ { "name" : "columns", "type" : "ANY", "isNullable" : true } ], "workspaceSchemaPath" : [ "local", "data" ] }
This is almost non-sensical. `columns` is reported as type `ANY` and nullable. But, `columns` is Repeated `VARCHAR` and repeated types cannot be nullable.
The conclusion is that the type information is virtually worthless and the `isNullable` information is worse than worthless: it is plain wrong.
The type information is valid only if the planner can inver types:
CREATE VIEW myView5 AS SELECT CAST(custId AS INTEGER) AS custId FROM `csvh/cust.csvh`;
The view file:
{ "name" : "myView5", "sql" : "SELECT CAST(`custId` AS INTEGER) AS `custId`\nFROM `csvh/cust.csvh`", "fields" : [ { "name" : "custId", "type" : "INTEGER", "isNullable" : true } ], "workspaceSchemaPath" : [ "local", "data" ] }
Note that the `type` is inferred from the cast, but `isNullable` is wrong because the underlying column is non-nullable:
SELECT modeOf(custId) FROM myView5 LIMIT 1; +-----------+ | EXPR$0 | +-----------+ | NOT NULL | +-----------+
Expected that Drill would run the underlying query as a `LIMIT 0` query to extract the actual column types, and use that in the view.
Or, expected that Drill would simply omit the column list from the view if the data is meaningless.