Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Resolved
-
None
-
None
-
None
Description
For a select * query referring to a schema-less table, Drill could return different column, depending on the physical operators the query involves:
Q1:
select * from cp.`employee.json` limit 3; +-------------+------------+------------+------------+-------------+----------------+------------+---------------+------------+------------+------------+---------------+-----------------+----------------+------------+-----------------+ | employee_id | full_name | first_name | last_name | position_id | position_title | store_id | department_id | birth_date | hire_date | salary | supervisor_id | education_level | marital_status | gender | management_role | +-------------+------------+------------+------------+-------------+----------------+------------+---------------+------------+------------+------------+---------------+-----------------+----------------+------------+-----------------+
Q2:
select * from cp.`employee.json` order by last_name limit 3; +------------+---------------+-----------------+-------------+------------+------------+------------+------------+------------+-----------------+----------------+-------------+----------------+------------+------------+---------------+ | birth_date | department_id | education_level | employee_id | first_name | full_name | gender | hire_date | last_name | management_role | marital_status | position_id | position_title | salary | store_id | supervisor_id | +------------+---------------+-----------------+-------------+------------+------------+------------+------------+------------+-----------------+----------------+-------------+----------------+------------+------------+---------------+
The difference between Q1 and Q2 is the order by clause. With order by clause in Q2, Drill will sort the column names alphabetically, while for Q1, the column names are in the same order as in the data source.
The underlying cause for such difference is that the sort or sort-based merger operator would require canonicalization, since the incoming batches could contain different schemas.
However, it would be better that such canonicalization is used only when the incoming batches have changing schemas. If all the incoming batches have identical schemas, no need to sort the column orders. With this fix, Drill will present the same column order in the result set, for a schema-less select * query, if there is no changing schemas from incoming data sources.
Attachments
Issue Links
- duplicates
-
DRILL-3101 Setting "slice_target" to 1 changes the order of the columns in a "select *" query with order by
- Resolved
- relates to
-
DRILL-5845 Columns returned by select with "ORDER BY" and "LIMIT" clauses are not in correct order.
- Resolved