Search in sources :

Example 16 with EntityName

use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.

the class SqlTaskNodeMeta method validateSql.

/**
 * 对sql进行粗略的校验
 *
 * @param sql
 * @param dependencyNodes
 * @return
 */
public static Optional<TisSqlFormatException> validateSql(String sql, List<String> dependencyNodes) {
    // Optional<TisSqlFormatException> result  = Optional.empty();
    SqlTaskNodeMeta taskNodeMeta = new SqlTaskNodeMeta();
    // 这个sql语句有错误,需要校验成错误,抛异常
    taskNodeMeta.setSql(sql);
    final IJoinTaskContext tskContext = new DftJoinTaskContext(ExecutePhaseRange.fullRange());
    final ITemplateContext tplContext = new ITemplateContext() {

        @Override
        public <T> T getContextValue(String key) {
            return null;
        }

        @Override
        public void putContextValue(String key, Object v) {
        }

        @Override
        public IJoinTaskContext getExecContext() {
            return tskContext;
        }
    };
    try {
        String pt = "20200703113848";
        ITabPartition p = () -> pt;
        Map<IDumpTable, ITabPartition> tabPartition = dependencyNodes.stream().collect(Collectors.toMap((r) -> EntityName.parse(r), (r) -> p));
        taskNodeMeta.getRewriteSql("testTaskName", new MockDumpPartition(tabPartition), new IPrimaryTabFinder() {

            @Override
            public Optional<TableMeta> getPrimaryTab(IDumpTable entityName) {
                return Optional.empty();
            }

            @Override
            public Map<EntityName, TabFieldProcessor> getTabFieldProcessorMap() {
                return Collections.emptyMap();
            }
        }, tplContext, false);
        return Optional.empty();
    } catch (Throwable e) {
        int indexOf;
        if ((indexOf = ExceptionUtils.indexOfType(e, TisSqlFormatException.class)) > -1) {
            TisSqlFormatException ex = (TisSqlFormatException) ExceptionUtils.getThrowables(e)[indexOf];
            // System.out.println(ex.summary());
            return Optional.of(ex);
        // assertEquals("base ref:gg can not find relevant table entity in map,mapSize:1,exist:[g:tis.commodity_goods],位置,行:1,列:44", ex.summary());
        } else {
            throw e;
        }
    }
}
Also used : LineIterator(org.apache.commons.io.LineIterator) IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) TableMeta(com.qlangtech.tis.sql.parser.er.TableMeta) StringUtils(org.apache.commons.lang.StringUtils) ColumnTransfer(com.qlangtech.tis.sql.parser.meta.ColumnTransfer) TIS(com.qlangtech.tis.TIS) DefaultDumpNodeMapContext(com.qlangtech.tis.sql.parser.utils.DefaultDumpNodeMapContext) Node(org.yaml.snakeyaml.nodes.Node) ExecutePhaseRange(com.qlangtech.tis.exec.ExecutePhaseRange) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScalarStyle(org.yaml.snakeyaml.DumperOptions.ScalarStyle) Method(java.lang.reflect.Method) ITabPartition(com.qlangtech.tis.fullbuild.indexbuild.ITabPartition) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) IJoinTaskContext(com.qlangtech.tis.order.center.IJoinTaskContext) Property(org.yaml.snakeyaml.introspector.Property) Collectors(java.util.stream.Collectors) SqlParser(com.facebook.presto.sql.parser.SqlParser) IOUtils(org.apache.commons.io.IOUtils) LineBreak(org.yaml.snakeyaml.DumperOptions.LineBreak) JSONObject(com.alibaba.fastjson.JSONObject) Pattern(java.util.regex.Pattern) ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) Joiner(com.google.common.base.Joiner) Types(java.sql.Types) java.util(java.util) JSONField(com.alibaba.fastjson.annotation.JSONField) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) Yaml(org.yaml.snakeyaml.Yaml) DumperOptions(org.yaml.snakeyaml.DumperOptions) IAppSourcePipelineController(com.qlangtech.tis.order.center.IAppSourcePipelineController) Lists(com.google.common.collect.Lists) TabFieldProcessor(com.qlangtech.tis.sql.parser.er.TabFieldProcessor) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) Position(com.qlangtech.tis.sql.parser.meta.Position) Constructor(org.yaml.snakeyaml.constructor.Constructor) NodeType(com.qlangtech.tis.sql.parser.meta.NodeType) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) com.qlangtech.tis.plugin.ds(com.qlangtech.tis.plugin.ds) FileUtils(org.apache.commons.io.FileUtils) Tag(org.yaml.snakeyaml.nodes.Tag) Maps(com.google.common.collect.Maps) TisSqlFormatException(com.qlangtech.tis.sql.parser.exception.TisSqlFormatException) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) FlowStyle(org.yaml.snakeyaml.DumperOptions.FlowStyle) JSON(com.alibaba.fastjson.JSON) ERRules(com.qlangtech.tis.sql.parser.er.ERRules) Expression(com.facebook.presto.sql.tree.Expression) ITemplateContext(com.qlangtech.tis.fullbuild.taskflow.ITemplateContext) java.io(java.io) IPrimaryTabFinder(com.qlangtech.tis.sql.parser.er.IPrimaryTabFinder) Representer(org.yaml.snakeyaml.representer.Representer) TypeDescription(org.yaml.snakeyaml.TypeDescription) Statement(com.facebook.presto.sql.tree.Statement) ITabPartition(com.qlangtech.tis.fullbuild.indexbuild.ITabPartition) IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) TisSqlFormatException(com.qlangtech.tis.sql.parser.exception.TisSqlFormatException) IPrimaryTabFinder(com.qlangtech.tis.sql.parser.er.IPrimaryTabFinder) JSONObject(com.alibaba.fastjson.JSONObject) IJoinTaskContext(com.qlangtech.tis.order.center.IJoinTaskContext) ITemplateContext(com.qlangtech.tis.fullbuild.taskflow.ITemplateContext)

Example 17 with EntityName

use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.

the class DataFlowAppSource method getTargetEntity.

@Override
public EntityName getTargetEntity() {
    try {
        SqlTaskNodeMeta.SqlDataFlowTopology workflowDetail = SqlTaskNodeMeta.getSqlDataFlowTopology(dataflowName);
        Objects.requireNonNull(workflowDetail, "workflowDetail can not be null");
        EntityName targetEntity = null;
        if (workflowDetail.isSingleTableModel()) {
            DependencyNode dumpNode = workflowDetail.getDumpNodes().get(0);
            targetEntity = dumpNode.parseEntityName();
        } else {
            SqlTaskNodeMeta finalN = workflowDetail.getFinalNode();
            targetEntity = EntityName.parse(finalN.getExportName());
        }
        return targetEntity;
    } catch (Exception e) {
        throw new RuntimeException(dataflowName, e);
    }
}
Also used : EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)

Aggregations

EntityName (com.qlangtech.tis.sql.parser.tuple.creator.EntityName)17 DependencyNode (com.qlangtech.tis.sql.parser.meta.DependencyNode)6 Collectors (java.util.stream.Collectors)5 StringUtils (org.apache.commons.lang.StringUtils)5 Connection (java.sql.Connection)4 ITISFileSystem (com.qlangtech.tis.fs.ITISFileSystem)3 TisGroupBy (com.qlangtech.tis.sql.parser.TisGroupBy)3 FuncFormat (com.qlangtech.tis.sql.parser.visitor.FuncFormat)3 Lists (com.google.common.collect.Lists)2 IDumpTable (com.qlangtech.tis.fullbuild.indexbuild.IDumpTable)2 LinkKeys (com.qlangtech.tis.sql.parser.er.LinkKeys)2 PrimaryTableMeta (com.qlangtech.tis.sql.parser.er.PrimaryTableMeta)2 TabCardinality (com.qlangtech.tis.sql.parser.er.TabCardinality)2 TableRelation (com.qlangtech.tis.sql.parser.er.TableRelation)2 FlatTableRelation (com.qlangtech.tis.sql.parser.stream.generate.FlatTableRelation)2 java.util (java.util)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Pattern (java.util.regex.Pattern)2