{
"version": "1.0",
"defaultSchema": "SALES"
"schemas": [
{
"name": "SALES",
"type": "custom",
"factory": "com.iflytek.edu.zx.CsvSchemaFactory",
"operand": {
"directory": "SALES.csv"
}
}
]
}
描述数据库名称、文件目录、shcema创建
##基本概念
schema ==> database
defaultSchema ==>登陆数据库时的默认数据库
schema factory ==>创建schema的工厂类
directory ==>数据存储
public class CsvSchemaFactory implements SchemaFactory {
@Override
public Schema create(SchemaPlus schemaPlus, String s, Map<String, Object> operand) {
return new CsvSchema(String.valueOf(operand.get("directory")));
}
}
获取表的映射关系
public class CsvSchema extends AbstractSchema {
private Map<String,Table> tableMap;
private String dataFile;
public CsvSchema(String dataFile){
this.dataFile = dataFile;
}
@Override
protected Map<String, Table> getTableMap() {
URL url = Resources.getResource(dataFile);
Source source = Sources.of(url);
if (tableMap == null) {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
builder.put(this.dataFile.split("\\.")[0],new CsvTable(source));
// 一个数据库有多个表名,这里初始化,大小写要注意了,TEST01是表名。
tableMap = builder.build();
}
return tableMap;
}
}
定义表的个字段的名称和类型
表支持的操作
如何遍历表对应的数据以满足查询语句