JDBC:DFS表的插入

教程中可以使用insert into t values()的写法,但是server中DFS并不支持insert 语句,请问是什么原因?

请先 登录 后评论

1 个回答

Yingnan Wang

原因是JDBC API在执行插入时,底层调用的是tableAppend接口,对应的server脚本是append函数

private int tableAppend() throws SQLException {
	if (unNameTable.size() > 1) {
		int insertRows = 0;
		List<Vector> cols = new ArrayList<>(unNameTable.size());
		try {
			for (int i = 0; i < colNames.size(); i++){
				Entity.DATA_TYPE dataType = colTypes_.get(i);
				List<Entity> values = unNameTable.get(colNames.get(i));
				Vector col = BasicEntityFactory.instance().createVectorWithDefaultValue(dataType, 1);
				col.set(0, (Scalar) values.get(tableRows));
				cols.add(col);
			}
			tableRows++;
		}catch (Exception e){
			return 0;
		}
		if (tableRows == unNameTable.get(colNames.get(0)).size()){
			unNameTable = null;
			tableRows = 0;
		}


		List<Entity> param = new ArrayList<>();
		BasicTable insertTable = new BasicTable(colNames, cols);
		param.add(insertTable);

		try {
			connection.run("append!{" + tableName + "}", param);
		} catch (IOException e) {
			e.printStackTrace();
		}

		cols = null;
		insertTable = null;

		return insertRows;
	}
	return 0;
}
请先 登录 后评论