一 源码下载
参照下文,下载编译源码
运行CsvTest 总体感知csv样例工程
输出
Test ignored.
Fred
Eric
John
Wilma
Alice
100, Fred, 10, , , 30, 25, true, false, 1996-08-03
110, Eric, 20, M, San Francisco, 3, 80, null, false, 2001-01-01
110, John, 40, M, Vancouver, 2, null, false, true, 2002-05-03
120, Wilma, 20, F, , 1, 5, null, true, 2005-09-07
130, Alice, 40, F, Vancouver, 2, null, false, true, 2007-01-01
Fred
Eric
John
Wilma
Alice
Test ignored.
Sales
Marketing
Accounts
100, Fred, 10, , , 30, 25, true, false, 1996-08-03
110, Eric, 20, M, San Francisco, 3, 80, null, false, 2001-01-01
110, John, 40, M, Vancouver, 2, null, false, true, 2002-05-03
120, Wilma, 20, F, , 1, 5, null, true, 2005-09-07
130, Alice, 40, F, Vancouver, 2, null, false, true, 2007-01-01
100, Fred, 10, , , 30, 25, true, false, 1996-08-03
110, Eric, 20, M, San Francisco, 3, 80, null, false, 2001-01-01
110, John, 40, M, Vancouver, 2, null, false, true, 2002-05-03
120, Wilma, 20, F, , 1, 5, null, true, 2005-09-07
130, Alice, 40, F, Vancouver, 2, null, false, true, 2007-01-01
二、简析1-model.json
model.json
{ "version": "1.0", "defaultSchema": "SALES", "schemas": [ { "name": "SALES", "type": "custom", "factory": "org.apache.calcite.adapter.csv.CsvSchemaFactory", "operand": { "directory": "sales" } } ] }
CsvSchemaFactory主要扫描directory中的文件,每个文件构建一个table
(1)CsvSchemaFactory
CsvSchemaFactory根据directory构建CsvSchema
CsvSchemaFactory::create
根据json中的directory和flavor 构建一个CsvSchema(directoryFile, flavor);
简要如下:
public class CsvSchemaFactory implements SchemaFactory { public static final CsvSchem