@@ -78,15 +78,15 @@ Execute a metadata query:
78
78
79
79
{% highlight bash %}
80
80
sqlline> !tables
81
- +------------ +-------------- +-------------+---------------+----------+ ------+
82
- | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE |
83
- +------------ +-------------- +-------------+---------------+----------+ ------+
84
- | null | SALES | DEPTS | TABLE | null | null |
85
- | null | SALES | EMPS | TABLE | null | null |
86
- | null | SALES | HOBBIES | TABLE | null | null |
87
- | null | metadata | COLUMNS | SYSTEM_TABLE | null | null |
88
- | null | metadata | TABLES | SYSTEM_TABLE | null | null |
89
- +------------ +-------------- +-------------+---------------+----------+ ------+
81
+ +-----------+------------- +------------+-------------- +---------+ ---------- +------------+ ----------- +---------------------------+---------- ------+
82
+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYPE_SCHEM | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION |
83
+ +-----------+------------- +------------+-------------- +---------+ ---------- +------------+ ----------- +---------------------------+---------- ------+
84
+ | | SALES | DEPTS | TABLE | | | | | | |
85
+ | | SALES | EMPS | TABLE | | | | | | |
86
+ | | SALES | SDEPTS | TABLE | | | | | | |
87
+ | | metadata | COLUMNS | SYSTEM TABLE | | | | | | |
88
+ | | metadata | TABLES | SYSTEM TABLE | | | | | | |
89
+ +-----------+------------- +------------+-------------- +---------+ ---------- +------------+ ----------- +---------------------------+---------- ------+
90
90
{% endhighlight %}
91
91
92
92
(JDBC experts, note: sqlline's <code >!tables</code > command is just executing
@@ -95,29 +95,29 @@ behind the scenes.
95
95
It has other commands to query JDBC metadata, such as <code >!columns</code > and <code >!describe</code >.)
96
96
97
97
As you can see there are 5 tables in the system: tables
98
- <code >EMPS</code >, <code >DEPTS</code > and <code >HOBBIES </code > in the current
98
+ <code >EMPS</code >, <code >DEPTS</code > and <code >SDEPTS </code > in the current
99
99
<code >SALES</code > schema, and <code >COLUMNS</code > and
100
100
<code >TABLES</code > in the system <code >metadata</code > schema. The
101
101
system tables are always present in Calcite, but the other tables are
102
102
provided by the specific implementation of the schema; in this case,
103
- the <code >EMPS</code > and <code >DEPTS </code > tables are based on the
104
- <code >EMPS.csv</code > and <code >DEPTS .csv</code > files in the
103
+ the <code >EMPS</code >, < code >DEPTS</ code > and <code >SDEPTS </code > tables are based on the
104
+ <code >EMPS.csv.gz </code >, < code >DEPTS.csv</ code > and <code >SDEPTS .csv</code > files in the
105
105
<code >resources/sales</code > directory.
106
106
107
107
Let's execute some queries on those tables, to show that Calcite is providing
108
108
a full implementation of SQL. First, a table scan:
109
109
110
110
{% highlight bash %}
111
111
sqlline> SELECT * FROM emps;
112
- +-------- +--------+--------- +---------+ ----------------+--------+-------+ ---+
113
- | EMPNO | NAME | DEPTNO | GENDER | CITY | EMPID | AGE | S |
114
- +-------- +--------+--------- +---------+ ----------------+--------+-------+ ---+
115
- | 100 | Fred | 10 | | | 30 | 25 | t |
116
- | 110 | Eric | 20 | M | San Francisco | 3 | 80 | n |
117
- | 110 | John | 40 | M | Vancouver | 2 | null | f |
118
- | 120 | Wilma | 20 | F | | 1 | 5 | n |
119
- | 130 | Alice | 40 | F | Vancouver | 2 | null | f |
120
- +-------- +--------+--------- +---------+ ----------------+--------+-------+ ---+
112
+ +-------+------- +--------+--------+---------------+ -------+ ------ +--------- +---------+--------- ---+
113
+ | EMPNO | NAME | DEPTNO | GENDER | CITY | EMPID | AGE | SLACKER | MANAGER | JOINEDAT |
114
+ +-------+------- +--------+--------+---------------+ -------+ ------ +--------- +---------+--------- ---+
115
+ | 100 | Fred | 10 | | | 30 | 25 | true | false | 1996-08-03 |
116
+ | 110 | Eric | 20 | M | San Francisco | 3 | 80 | | false | 2001-01-01 |
117
+ | 110 | John | 40 | M | Vancouver | 2 | null | false | true | 2002-05-03 |
118
+ | 120 | Wilma | 20 | F | | 1 | 5 | | true | 2005-09-07 |
119
+ | 130 | Alice | 40 | F | Vancouver | 2 | null | false | true | 2007-01-01 |
120
+ +-------+------- +--------+--------+---------------+ -------+ ------ +--------- +---------+--------- ---+
121
121
{% endhighlight %}
122
122
123
123
Now JOIN and GROUP BY:
@@ -277,11 +277,11 @@ private Table createTable(File file) {
277
277
}
278
278
{% endhighlight %}
279
279
280
- The schema scans the directory and finds all files whose name ends
281
- with ".csv" and creates tables for them. In this case, the directory
280
+ The schema scans the directory, finds all files with the appropriate extension,
281
+ and creates tables for them. In this case, the directory
282
282
is <code >sales</code > and contains files
283
- <code >EMPS.csv</code > and <code >DEPTS .csv</code >, which these become
284
- the tables <code >EMPS</code > and <code >DEPTS </code >.
283
+ <code >EMPS.csv.gz </code >, < code >DEPTS.csv</ code > and <code >SDEPTS .csv</code >, which these become
284
+ the tables <code >EMPS</code >, < code >DEPTS</ code > and <code >SDEPTS </code >.
285
285
286
286
## Tables and views in schemas
287
287
@@ -480,16 +480,15 @@ sqlline> explain plan for select name from emps;
480
480
+-----------------------------------------------------+
481
481
| PLAN |
482
482
+-----------------------------------------------------+
483
- | EnumerableCalcRel (expr #0 ..9=[ {inputs}] , NAME=[ $t1] ) |
483
+ | EnumerableCalc (expr #0 ..9=[ {inputs}] , NAME=[ $t1] ) |
484
484
| EnumerableTableScan(table=[[ SALES, EMPS]] ) |
485
485
+-----------------------------------------------------+
486
486
sqlline> !connect jdbc:calcite: model =src/test/resources/smart.json admin admin
487
487
sqlline> explain plan for select name from emps;
488
488
+-----------------------------------------------------+
489
489
| PLAN |
490
490
+-----------------------------------------------------+
491
- | EnumerableCalcRel(expr #0 ..9=[ {inputs}] , NAME=[ $t1] ) |
492
- | CsvTableScan(table=[[ SALES, EMPS]] ) |
491
+ | CsvTableScan(table=[[ SALES, EMPS]] , fields=[[ 1]] ) |
493
492
+-----------------------------------------------------+
494
493
{% endhighlight %}
495
494
0 commit comments