use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project plugins by qlangtech.
the class JoinHiveTask method processJoinTask.
/**
* 处理join表,是否需要自动创建表或者删除重新创建表
*
* @param sql
*/
private void processJoinTask(String sql) {
try {
final HiveInsertFromSelectParser insertParser = getSQLParserResult(sql);
final Connection conn = this.getTaskContext().getObj();
// final DumpTable dumpTable =
// DumpTable.createTable(insertParser.getTargetTableName());
final EntityName dumpTable = EntityName.parse(this.getName());
final String path = FSHistoryFileUtils.getJoinTableStorePath(fileSystem.getRootDir(), dumpTable).replaceAll("\\.", Path.SEPARATOR);
if (fileSystem == null) {
throw new IllegalStateException("fileSys can not be null");
}
ITISFileSystem fs = fileSystem;
IPath parent = fs.getPath(path);
initializeHiveTable(this.fileSystem, parent, mrEngine, HdfsFormat.DEFAULT_FORMAT, insertParser.getCols(), insertParser.getColsExcludePartitionCols(), conn, dumpTable, ITableDumpConstant.MAX_PARTITION_SAVE);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.
the class TestSqlTaskNode method testParseWithSingleDumpNode.
public void testParseWithSingleDumpNode() {
EntityName exportName = EntityName.parse("employees.employee");
// , NodeType nodetype, IDumpNodeMapContext dumpNodesContext
IDumpNodeMapContext dumpNodesContext = EasyMock.createMock("dumpNodesContext", IDumpNodeMapContext.class);
EasyMock.expect(dumpNodesContext.nullableMatch(exportName.getTabName())).andReturn(exportName);
SqlTaskNode taskNode = new SqlTaskNode(exportName, NodeType.DUMP, dumpNodesContext);
taskNode.setContent("SELECT e.a,e.b,e.c FROM employee e");
EasyMock.replay(dumpNodesContext);
TableTupleCreator tupleCreator = taskNode.parse(true);
assertNotNull("tupleCreator can not be null", tupleCreator);
EasyMock.verify(dumpNodesContext);
}
use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.
the class FlatTableRelation method buildInvokeQueryHeaderByTailerInfo.
/**
* 执行调用通过子查询父表逻辑
*
* @return
*/
public FuncFormat buildInvokeQueryHeaderByTailerInfo() {
FuncFormat r = new FuncFormat();
final String paramsList = this.getHeaderKeys().stream().map((m) -> {
TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(m.getHeadLinkKey());
r.appendLine("val " + col.getJavaVarName() + " = row.getColumn(\"" + m.getTailerLinkKey() + "\")");
return col.getJavaVarName();
}).collect(Collectors.joining(","));
EntityName headerEntity = this.getHeaderEntity();
r.startLine("val " + (this.isHeaderMulti() ? headerEntity.entities() + ": List[RowMap] " : headerEntity.getJavaEntityName() + ": RowMap ") + " = this." + this.buildQueryHeaderByTailerInfoMethodName() + "(" + paramsList + ") ");
return r;
}
use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.
the class FlatTableRelation method buildInvokeQueryHeaderByTailerInfoResultProcess.
/**
* 创建查询结处理
*
* @param primary
* @param preTableRelation 上一个表关联关系
* @return
*/
public FuncFormat buildInvokeQueryHeaderByTailerInfoResultProcess(PrimaryTableMeta primary, FlatTableRelation preTableRelation) {
FuncFormat f = new FuncFormat();
EntityName headerEntity = this.getHeaderEntity();
f.appendLine("val " + headerEntity.getJavaEntityName() + "Meta : AliasList = tabColumnMetaMap.get(\"" + headerEntity.getTabName() + "\");");
// TableRelation.FinalLinkKey finalLinkKey = getFinalLinkKey(primary.getDBPrimayKeyName().getName(), preTableRelation);
// final String pkColGetter = headerEntity.createColGetterLiteria(finalLinkKey.linkKeyName);
// headerEntity.getJavaEntityName() + "Meta.getColMeta(\"" + finalLinkKey.linkKeyName + "\")";
final String createCompositePKLiteria = primary.createCompositePK(headerEntity.getJavaEntityName() + "Meta", this.isHeaderMulti() ? "r" : headerEntity.getJavaEntityName(), true, preTableRelation);
if (this.isHeaderMulti()) {
// 遍历结果集
f.buildRowMapTraverseLiteria(headerEntity, (mm) -> {
mm.startLine("pushPojo2Queue(" + createCompositePKLiteria + ", row)").append("/*gencode3*/");
// mm.startLine("pushPojo2Queue(new CompositePK("
// + headerEntity.createColValLiteria(finalLinkKey.linkKeyName, "r") + ", r), row)");
});
} else {
f.methodBody("if(" + headerEntity.getJavaEntityName() + " != null)", (mm) -> {
mm.startLine("return " + createCompositePKLiteria).append("/*gencode4*/");
// mm.startLine("return new CompositePK(" + headerEntity.createColValLiteria("dddddd")
// + "," + headerEntity.getJavaEntityName() + ")").append("/*codegen4*/");
});
}
f.startLine(" null");
return f;
}
use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.
the class FlatTableRelation method buildQueryHeaderByTailerInfo.
/**
* 通过子表查询主表(head),生成查询方法
*
* @param extraHeaderColKeys 额外的col
* @return
*/
public FuncFormat buildQueryHeaderByTailerInfo(final Set<String> extraHeaderColKeys) {
// final String paramsList = this.getJoinerKeys().stream().map((jk) -> {
// TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(jk.getChildKey());
// return col.getJavaVarName() + " : String";
// }).collect(Collectors.joining(","));
// EntityName headerEntity = relation.getHeader().parseEntityName();
final EntityName tailerEntity = this.getTailerEntity();
final EntityName headEntity = this.getHeaderEntity();
final String methodToken = "private def " + this.buildQueryHeaderByTailerInfoMethodName() + "(" + this.getJoinerKeysQueryMethodParamsLiteria() + ") : " + (this.isHeaderMulti() ? "List[RowMap]" : "RowMap") + " =";
FuncFormat r = new FuncFormat();
r.methodBody(methodToken, (m) -> {
// 定义结果集对象
m.startLine(headEntity.buildDefineRowMapListLiteria());
// 创建查询对象
m.startLine(headEntity.buildDefineCriteriaEqualLiteria());
// << 设置查询条件
// this.getJoinerKeys().stream().forEach((mm) -> {
// TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(mm.getChildKey());
// m.appendLine(col.buildDefineParam());
// });
m.returnLine();
m.startLine(headEntity.buildCreateCriteriaLiteria());
this.getHeaderKeys().stream().forEach((mm) -> {
TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(mm.getHeadLinkKey());
m.append(col.buildPropCriteriaEqualLiteria());
});
// 设置查询条件>>
// 设置select的列
Set<String> selCols = this.getHeaderKeys().stream().map((link) -> link.getHeadLinkKey()).collect(Collectors.toSet());
selCols.addAll(extraHeaderColKeys);
m.startLine(headEntity.buildAddSelectorColsLiteria(selCols));
// 执行dao查询
m.startLine(headEntity.buildExecuteQueryDAOLiteria());
if (this.isHeaderMulti()) {
m.startLine("return " + headEntity.entities());
} else {
m.methodBody("for ( ( r:RowMap) <- " + headEntity.entities() + ".asScala)", (rt) -> {
rt.startLine("return r");
});
m.startLine("null");
}
});
return r;
}
Aggregations