Skip to content

Commit 8094bc3

Browse files
guiyanakuangzabetak
authored andcommittedJan 7, 2022
Site: Improve HTML tables display & update CSV tutorial
1. Allow code pre-wrap in tables. 2. Display horizontal scrollbar in tables when content is too large and cannot be wrapped. 3. Update CSV tutorial example based on current code. Close apache#2632
1 parent ea4a5f3 commit 8094bc3

File tree

4 files changed

+67
-30
lines changed

4 files changed

+67
-30
lines changed
 

‎site/_docs/adapter.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,18 @@ as implemented by Avatica's
109109
To make a connection to a single schema based on a built-in schema type, you don't need to specify
110110
a model. For example,
111111

112-
`jdbc:calcite:schemaType=JDBC; schema.jdbcUser=SCOTT; schema.jdbcPassword=TIGER; schema.jdbcUrl=jdbc:hsqldb:res:foodmart`
112+
{% highlight text %}
113+
jdbc:calcite:schemaType=JDBC; schema.jdbcUser=SCOTT; schema.jdbcPassword=TIGER; schema.jdbcUrl=jdbc:hsqldb:res:foodmart
114+
{% endhighlight %}
113115

114116
creates a connection with a schema mapped via the JDBC schema adapter to the foodmart database.
115117

116118
Similarly, you can connect to a single schema based on a user-defined schema adapter.
117119
For example,
118120

119-
`jdbc:calcite:schemaFactory=org.apache.calcite.adapter.cassandra.CassandraSchemaFactory; schema.host=localhost; schema.keyspace=twissandra`
121+
{% highlight text %}
122+
jdbc:calcite:schemaFactory=org.apache.calcite.adapter.cassandra.CassandraSchemaFactory; schema.host=localhost; schema.keyspace=twissandra
123+
{% endhighlight %}
120124

121125
makes a connection to the Cassandra adapter, equivalent to writing the following model file:
122126

‎site/_docs/tutorial.md

+27-28
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ Execute a metadata query:
7878

7979
{% highlight bash %}
8080
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+
+-----------+-------------+------------+--------------+---------+----------+------------+-----------+---------------------------+----------------+
9090
{% endhighlight %}
9191

9292
(JDBC experts, note: sqlline's <code>!tables</code> command is just executing
@@ -95,29 +95,29 @@ behind the scenes.
9595
It has other commands to query JDBC metadata, such as <code>!columns</code> and <code>!describe</code>.)
9696

9797
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
9999
<code>SALES</code> schema, and <code>COLUMNS</code> and
100100
<code>TABLES</code> in the system <code>metadata</code> schema. The
101101
system tables are always present in Calcite, but the other tables are
102102
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
105105
<code>resources/sales</code> directory.
106106

107107
Let's execute some queries on those tables, to show that Calcite is providing
108108
a full implementation of SQL. First, a table scan:
109109

110110
{% highlight bash %}
111111
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+
+-------+-------+--------+--------+---------------+-------+------+---------+---------+------------+
121121
{% endhighlight %}
122122

123123
Now JOIN and GROUP BY:
@@ -277,11 +277,11 @@ private Table createTable(File file) {
277277
}
278278
{% endhighlight %}
279279

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
282282
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>.
285285

286286
## Tables and views in schemas
287287

@@ -480,16 +480,15 @@ sqlline> explain plan for select name from emps;
480480
+-----------------------------------------------------+
481481
| PLAN |
482482
+-----------------------------------------------------+
483-
| EnumerableCalcRel(expr#0..9=[{inputs}], NAME=[$t1]) |
483+
| EnumerableCalc(expr#0..9=[{inputs}], NAME=[$t1]) |
484484
| EnumerableTableScan(table=[[SALES, EMPS]]) |
485485
+-----------------------------------------------------+
486486
sqlline> !connect jdbc:calcite:model=src/test/resources/smart.json admin admin
487487
sqlline> explain plan for select name from emps;
488488
+-----------------------------------------------------+
489489
| PLAN |
490490
+-----------------------------------------------------+
491-
| EnumerableCalcRel(expr#0..9=[{inputs}], NAME=[$t1]) |
492-
| CsvTableScan(table=[[SALES, EMPS]]) |
491+
| CsvTableScan(table=[[SALES, EMPS]], fields=[[1]]) |
493492
+-----------------------------------------------------+
494493
{% endhighlight %}
495494

‎site/_plugins/wrap_table.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to you under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
require 'nokogiri'
17+
18+
Jekyll::Hooks.register [:pages, :documents], :post_render do |post|
19+
if post.path.end_with?(".md")
20+
doc = Nokogiri::HTML(post.output)
21+
doc.search("table").wrap("<div class=\"scroll-table-style\">")
22+
post.output = doc.to_html
23+
end
24+
end

‎site/_sass/_style.scss

+10
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,23 @@ blockquote {
705705
/* Tables */
706706

707707
table {
708+
/* Allow code inside tables to wrap when there is no space */
709+
pre,
710+
code {
711+
white-space: pre-wrap;
712+
}
708713
width: 100%;
709714
background-color: #555;
710715
margin: .5em 0;
711716
@include border-radius(5px);
712717
@include box-shadow(0 1px 3px rgba(0,0,0,.3));
713718
}
714719

720+
/* The CSS class is added via _plugins/wrap_table.rb plugin to enable horizontal scrolling */
721+
.scroll-table-style {
722+
overflow-x: auto;
723+
}
724+
715725
thead {
716726
@include border-top-left-radius(5px);
717727
@include border-top-right-radius(5px);

0 commit comments

Comments
 (0)
Please sign in to comment.