Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
e6aeea73
Unverified
Commit
e6aeea73
authored
Mar 22, 2023
by
aiwenmo
Committed by
GitHub
Mar 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Optimization-1753][core] Remove deprecated lineage code (#1758)
Co-authored-by:
wenmo
<
32723967+wenmo@users.noreply.github.com
>
parent
63ea7d98
Show whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
7 additions
and
3301 deletions
+7
-3301
Explainer.java
dinky-core/src/main/java/org/dinky/explainer/Explainer.java
+0
-292
CABuilder.java
...-core/src/main/java/org/dinky/explainer/ca/CABuilder.java
+0
-132
CAGenerator.java
...ore/src/main/java/org/dinky/explainer/ca/CAGenerator.java
+0
-25
ColumnCA.java
...y-core/src/main/java/org/dinky/explainer/ca/ColumnCA.java
+0
-160
ColumnCAGenerator.java
...c/main/java/org/dinky/explainer/ca/ColumnCAGenerator.java
+0
-297
ColumnCANode.java
...re/src/main/java/org/dinky/explainer/ca/ColumnCANode.java
+0
-49
ColumnCAResult.java
.../src/main/java/org/dinky/explainer/ca/ColumnCAResult.java
+0
-99
ICA.java
dinky-core/src/main/java/org/dinky/explainer/ca/ICA.java
+0
-27
NodeRel.java
dinky-core/src/main/java/org/dinky/explainer/ca/NodeRel.java
+0
-73
TableCA.java
dinky-core/src/main/java/org/dinky/explainer/ca/TableCA.java
+0
-172
TableCAGenerator.java
...rc/main/java/org/dinky/explainer/ca/TableCAGenerator.java
+0
-189
TableCANode.java
...ore/src/main/java/org/dinky/explainer/ca/TableCANode.java
+0
-68
TableCAResult.java
...e/src/main/java/org/dinky/explainer/ca/TableCAResult.java
+0
-65
LineageBuilder.java
...main/java/org/dinky/explainer/lineage/LineageBuilder.java
+4
-116
LineageColumnGenerator.java
...a/org/dinky/explainer/lineage/LineageColumnGenerator.java
+0
-399
LineageTable.java
...c/main/java/org/dinky/explainer/lineage/LineageTable.java
+0
-14
LineageTableGenerator.java
...va/org/dinky/explainer/lineage/LineageTableGenerator.java
+0
-87
AbstractTrans.java
...rc/main/java/org/dinky/explainer/trans/AbstractTrans.java
+0
-199
Field.java
...y-core/src/main/java/org/dinky/explainer/trans/Field.java
+0
-58
OperatorTrans.java
...rc/main/java/org/dinky/explainer/trans/OperatorTrans.java
+0
-138
Predecessor.java
.../src/main/java/org/dinky/explainer/trans/Predecessor.java
+0
-58
SinkTrans.java
...re/src/main/java/org/dinky/explainer/trans/SinkTrans.java
+0
-109
SourceTrans.java
.../src/main/java/org/dinky/explainer/trans/SourceTrans.java
+0
-114
Trans.java
...y-core/src/main/java/org/dinky/explainer/trans/Trans.java
+0
-53
TransGenerator.java
...c/main/java/org/dinky/explainer/trans/TransGenerator.java
+0
-89
FlinkSqlPlus.java
dinky-core/src/main/java/org/dinky/plus/FlinkSqlPlus.java
+0
-123
FlinkSqlPlusTest.java
...y-core/src/test/java/org/dinky/core/FlinkSqlPlusTest.java
+0
-93
SimpleTaskForm.tsx
...omponents/Studio/StudioTree/components/SimpleTaskForm.tsx
+1
-1
UpdateCatalogueForm.tsx
...ents/Studio/StudioTree/components/UpdateCatalogueForm.tsx
+1
-1
UploadModal.tsx
...c/components/Studio/StudioTree/components/UploadModal.tsx
+1
-1
No files found.
dinky-core/src/main/java/org/dinky/explainer/Explainer.java
View file @
e6aeea73
...
@@ -24,16 +24,6 @@ import org.dinky.constant.FlinkSQLConstant;
...
@@ -24,16 +24,6 @@ import org.dinky.constant.FlinkSQLConstant;
import
org.dinky.context.DinkyClassLoaderContextHolder
;
import
org.dinky.context.DinkyClassLoaderContextHolder
;
import
org.dinky.context.JarPathContextHolder
;
import
org.dinky.context.JarPathContextHolder
;
import
org.dinky.executor.Executor
;
import
org.dinky.executor.Executor
;
import
org.dinky.explainer.ca.ColumnCA
;
import
org.dinky.explainer.ca.ColumnCAResult
;
import
org.dinky.explainer.ca.NodeRel
;
import
org.dinky.explainer.ca.TableCA
;
import
org.dinky.explainer.ca.TableCAGenerator
;
import
org.dinky.explainer.ca.TableCAResult
;
import
org.dinky.explainer.lineage.LineageColumnGenerator
;
import
org.dinky.explainer.lineage.LineageTableGenerator
;
import
org.dinky.explainer.trans.Trans
;
import
org.dinky.explainer.trans.TransGenerator
;
import
org.dinky.function.data.model.UDF
;
import
org.dinky.function.data.model.UDF
;
import
org.dinky.function.util.UDFUtil
;
import
org.dinky.function.util.UDFUtil
;
import
org.dinky.interceptor.FlinkInterceptor
;
import
org.dinky.interceptor.FlinkInterceptor
;
...
@@ -50,18 +40,15 @@ import org.dinky.process.model.ProcessEntity;
...
@@ -50,18 +40,15 @@ import org.dinky.process.model.ProcessEntity;
import
org.dinky.result.ExplainResult
;
import
org.dinky.result.ExplainResult
;
import
org.dinky.result.SqlExplainResult
;
import
org.dinky.result.SqlExplainResult
;
import
org.dinky.trans.Operations
;
import
org.dinky.trans.Operations
;
import
org.dinky.utils.FlinkUtil
;
import
org.dinky.utils.LogUtil
;
import
org.dinky.utils.LogUtil
;
import
org.dinky.utils.SqlUtil
;
import
org.dinky.utils.SqlUtil
;
import
org.dinky.utils.URLUtils
;
import
org.dinky.utils.URLUtils
;
import
org.apache.flink.runtime.rest.messages.JobPlanInfo
;
import
org.apache.flink.runtime.rest.messages.JobPlanInfo
;
import
org.apache.flink.table.catalog.CatalogManager
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
...
@@ -82,12 +69,6 @@ public class Explainer {
...
@@ -82,12 +69,6 @@ public class Explainer {
private
String
sqlSeparator
=
FlinkSQLConstant
.
SEPARATOR
;
private
String
sqlSeparator
=
FlinkSQLConstant
.
SEPARATOR
;
private
ObjectMapper
mapper
=
new
ObjectMapper
();
private
ObjectMapper
mapper
=
new
ObjectMapper
();
public
Explainer
(
Executor
executor
)
{
this
.
executor
=
executor
;
this
.
useStatementSet
=
true
;
init
();
}
public
Explainer
(
Executor
executor
,
boolean
useStatementSet
)
{
public
Explainer
(
Executor
executor
,
boolean
useStatementSet
)
{
this
.
executor
=
executor
;
this
.
executor
=
executor
;
this
.
useStatementSet
=
useStatementSet
;
this
.
useStatementSet
=
useStatementSet
;
...
@@ -104,10 +85,6 @@ public class Explainer {
...
@@ -104,10 +85,6 @@ public class Explainer {
sqlSeparator
=
SystemConfiguration
.
getInstances
().
getSqlSeparator
();
sqlSeparator
=
SystemConfiguration
.
getInstances
().
getSqlSeparator
();
}
}
public
static
Explainer
build
(
Executor
executor
)
{
return
new
Explainer
(
executor
,
false
,
";"
);
}
public
static
Explainer
build
(
Executor
executor
,
boolean
useStatementSet
,
String
sqlSeparator
)
{
public
static
Explainer
build
(
Executor
executor
,
boolean
useStatementSet
,
String
sqlSeparator
)
{
return
new
Explainer
(
executor
,
useStatementSet
,
sqlSeparator
);
return
new
Explainer
(
executor
,
useStatementSet
,
sqlSeparator
);
}
}
...
@@ -174,50 +151,6 @@ public class Explainer {
...
@@ -174,50 +151,6 @@ public class Explainer {
return
udfList
;
return
udfList
;
}
}
public
List
<
SqlExplainResult
>
explainSqlResult
(
String
statement
)
{
String
[]
sqls
=
SqlUtil
.
getStatements
(
statement
,
sqlSeparator
);
List
<
SqlExplainResult
>
sqlExplainRecords
=
new
ArrayList
<>();
int
index
=
1
;
for
(
String
item
:
sqls
)
{
SqlExplainResult
record
=
new
SqlExplainResult
();
String
sql
=
""
;
try
{
sql
=
FlinkInterceptor
.
pretreatStatement
(
executor
,
item
);
if
(
Asserts
.
isNullString
(
sql
))
{
continue
;
}
SqlType
operationType
=
Operations
.
getOperationType
(
sql
);
if
(
operationType
.
equals
(
SqlType
.
INSERT
)
||
operationType
.
equals
(
SqlType
.
SELECT
))
{
record
=
executor
.
explainSqlRecord
(
sql
);
if
(
Asserts
.
isNull
(
record
))
{
continue
;
}
}
else
{
record
=
executor
.
explainSqlRecord
(
sql
);
if
(
Asserts
.
isNull
(
record
))
{
continue
;
}
executor
.
executeSql
(
sql
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
record
.
setError
(
e
.
getMessage
());
record
.
setExplainTrue
(
false
);
record
.
setExplainTime
(
LocalDateTime
.
now
());
record
.
setSql
(
sql
);
record
.
setIndex
(
index
);
sqlExplainRecords
.
add
(
record
);
break
;
}
record
.
setExplainTrue
(
true
);
record
.
setExplainTime
(
LocalDateTime
.
now
());
record
.
setSql
(
sql
);
record
.
setIndex
(
index
++);
sqlExplainRecords
.
add
(
record
);
}
return
sqlExplainRecords
;
}
public
ExplainResult
explainSql
(
String
statement
)
{
public
ExplainResult
explainSql
(
String
statement
)
{
ProcessEntity
process
=
ProcessContextHolder
.
getProcess
();
ProcessEntity
process
=
ProcessContextHolder
.
getProcess
();
process
.
info
(
"Start explain FlinkSQL..."
);
process
.
info
(
"Start explain FlinkSQL..."
);
...
@@ -381,231 +314,6 @@ public class Explainer {
...
@@ -381,231 +314,6 @@ public class Explainer {
}
}
}
}
private
List
<
TableCAResult
>
generateTableCA
(
String
statement
,
boolean
onlyTable
)
{
List
<
SqlExplainResult
>
sqlExplainRecords
=
explainSqlResult
(
statement
);
List
<
String
>
strPlans
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
sqlExplainRecords
.
size
();
i
++)
{
if
(
Asserts
.
isNotNull
(
sqlExplainRecords
.
get
(
i
).
getType
())
&&
sqlExplainRecords
.
get
(
i
).
getType
().
contains
(
FlinkSQLConstant
.
DML
))
{
strPlans
.
add
(
sqlExplainRecords
.
get
(
i
).
getSql
());
}
}
List
<
TableCAResult
>
results
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
strPlans
.
size
();
i
++)
{
List
<
Trans
>
trans
=
translateTrans
(
translateObjectNode
(
strPlans
.
get
(
i
)));
TableCAGenerator
generator
=
TableCAGenerator
.
build
(
trans
);
if
(
onlyTable
)
{
generator
.
translateOnlyTable
();
}
else
{
generator
.
translate
();
}
results
.
add
(
generator
.
getResult
());
}
if
(
results
.
size
()
>
0
)
{
CatalogManager
catalogManager
=
executor
.
getCatalogManager
();
for
(
int
i
=
0
;
i
<
results
.
size
();
i
++)
{
TableCA
sinkTableCA
=
(
TableCA
)
results
.
get
(
i
).
getSinkTableCA
();
if
(
Asserts
.
isNotNull
(
sinkTableCA
))
{
sinkTableCA
.
setFields
(
FlinkUtil
.
getFieldNamesFromCatalogManager
(
catalogManager
,
sinkTableCA
.
getCatalog
(),
sinkTableCA
.
getDatabase
(),
sinkTableCA
.
getTable
()));
}
}
}
return
results
;
}
public
List
<
TableCAResult
>
generateTableCA
(
String
statement
)
{
return
generateTableCA
(
statement
,
true
);
}
public
List
<
TableCAResult
>
explainSqlTableColumnCA
(
String
statement
)
{
return
generateTableCA
(
statement
,
false
);
}
public
List
<
ColumnCAResult
>
explainSqlColumnCA
(
String
statement
)
{
List
<
SqlExplainResult
>
sqlExplainRecords
=
explainSqlResult
(
statement
);
List
<
String
>
strPlans
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
sqlExplainRecords
.
size
();
i
++)
{
if
(
Asserts
.
isNotNull
(
sqlExplainRecords
.
get
(
i
).
getType
())
&&
sqlExplainRecords
.
get
(
i
).
getType
().
contains
(
"DML"
))
{
strPlans
.
add
(
sqlExplainRecords
.
get
(
i
).
getSql
());
}
}
List
<
ColumnCAResult
>
results
=
new
ArrayList
<>();
// statementsets
if
(
useStatementSet
)
{
List
<
Trans
>
trans
=
translateTrans
(
translateObjectNode
(
strPlans
));
LineageColumnGenerator
generator
=
LineageColumnGenerator
.
build
(
trans
);
LineageTableGenerator
tableGenerator
=
LineageTableGenerator
.
build
(
trans
);
tableGenerator
.
translate
();
generator
.
setTableCAS
(
tableGenerator
.
getTables
());
generator
.
translate
();
ColumnCAResult
columnCAResult
=
new
ColumnCAResult
(
generator
);
correctColumn
(
columnCAResult
);
correctSinkSets
(
columnCAResult
);
results
.
add
(
columnCAResult
);
}
else
{
for
(
int
i
=
0
;
i
<
strPlans
.
size
();
i
++)
{
List
<
Trans
>
trans
=
translateTrans
(
translateObjectNode
(
strPlans
.
get
(
i
)));
LineageColumnGenerator
generator
=
LineageColumnGenerator
.
build
(
trans
);
LineageTableGenerator
tableGenerator
=
LineageTableGenerator
.
build
(
trans
);
tableGenerator
.
translate
();
generator
.
setTableCAS
(
tableGenerator
.
getTables
());
generator
.
translate
();
ColumnCAResult
columnCAResult
=
new
ColumnCAResult
(
generator
);
correctColumn
(
columnCAResult
);
results
.
add
(
columnCAResult
);
}
}
return
results
;
}
private
void
correctColumn
(
ColumnCAResult
columnCAResult
)
{
for
(
TableCA
tableCA
:
columnCAResult
.
getTableCAS
())
{
CatalogManager
catalogManager
=
executor
.
getCatalogManager
();
List
<
String
>
columnList
=
FlinkUtil
.
getFieldNamesFromCatalogManager
(
catalogManager
,
tableCA
.
getCatalog
(),
tableCA
.
getDatabase
(),
tableCA
.
getTable
());
List
<
String
>
fields
=
tableCA
.
getFields
();
List
<
String
>
oldFields
=
new
ArrayList
<>();
oldFields
.
addAll
(
fields
);
if
(
tableCA
.
getType
().
equals
(
"Data Sink"
))
{
for
(
int
i
=
0
;
i
<
columnList
.
size
();
i
++)
{
String
sinkColumnName
=
columnList
.
get
(
i
);
if
(!
sinkColumnName
.
equals
(
oldFields
.
get
(
i
)))
{
for
(
Map
.
Entry
<
Integer
,
ColumnCA
>
item
:
columnCAResult
.
getColumnCASMaps
().
entrySet
())
{
ColumnCA
columnCA
=
item
.
getValue
();
if
(
columnCA
.
getTableId
().
equals
(
tableCA
.
getId
())
&&
columnCA
.
getName
().
equals
(
oldFields
.
get
(
i
)))
{
columnCA
.
setName
(
sinkColumnName
);
fields
.
set
(
i
,
sinkColumnName
);
}
}
}
}
}
}
for
(
TableCA
tableCA
:
columnCAResult
.
getTableCAS
())
{
CatalogManager
catalogManager
=
executor
.
getCatalogManager
();
List
<
String
>
columnList
=
FlinkUtil
.
getFieldNamesFromCatalogManager
(
catalogManager
,
tableCA
.
getCatalog
(),
tableCA
.
getDatabase
(),
tableCA
.
getTable
());
List
<
String
>
fields
=
tableCA
.
getFields
();
int
i
=
0
;
List
<
Integer
>
idList
=
new
ArrayList
<>();
while
(
i
<
fields
.
size
())
{
if
(!
columnList
.
contains
(
fields
.
get
(
i
)))
{
for
(
Map
.
Entry
<
Integer
,
ColumnCA
>
item
:
columnCAResult
.
getColumnCASMaps
().
entrySet
())
{
if
(
item
.
getValue
().
getName
().
equals
(
fields
.
get
(
i
))
&&
item
.
getValue
().
getTableId
().
equals
(
tableCA
.
getId
()))
{
idList
.
add
(
item
.
getValue
().
getId
());
break
;
}
}
fields
.
remove
(
i
);
}
else
{
i
++;
}
}
for
(
Integer
id
:
idList
)
{
for
(
NodeRel
nodeRel
:
columnCAResult
.
getColumnCASRelChain
())
{
if
(
nodeRel
.
getPreId
().
equals
(
id
))
{
columnCAResult
.
getColumnCASMaps
().
remove
(
id
);
columnCAResult
.
getColumnCASRelChain
().
remove
(
nodeRel
);
break
;
}
}
}
}
}
private
void
correctSinkSets
(
ColumnCAResult
columnCAResult
)
{
for
(
TableCA
tableCA
:
columnCAResult
.
getTableCAS
())
{
if
(
tableCA
.
getType
().
equals
(
"Data Sink"
))
{
for
(
Map
.
Entry
<
Integer
,
ColumnCA
>
item
:
columnCAResult
.
getColumnCASMaps
().
entrySet
())
{
if
(
item
.
getValue
().
getTableId
().
equals
(
tableCA
.
getId
()))
{
List
<
NodeRel
>
addNodeRels
=
new
ArrayList
<>();
List
<
NodeRel
>
delNodeRels
=
new
ArrayList
<>();
for
(
NodeRel
nodeRel
:
columnCAResult
.
getColumnCASRelChain
())
{
if
(
nodeRel
.
getPreId
().
equals
(
item
.
getValue
().
getId
()))
{
for
(
NodeRel
nodeRel2
:
columnCAResult
.
getColumnCASRelChain
())
{
if
(
columnCAResult
.
getColumnCASMaps
()
.
containsKey
(
nodeRel2
.
getSufId
())
&&
columnCAResult
.
getColumnCASMaps
()
.
containsKey
(
nodeRel2
.
getPreId
())
&&
columnCAResult
.
getColumnCASMaps
()
.
containsKey
(
nodeRel
.
getSufId
())
&&
columnCAResult
.
getColumnCASMaps
()
.
get
(
nodeRel2
.
getSufId
())
.
getTableId
()
.
equals
(
columnCAResult
.
getColumnCASMaps
()
.
get
(
nodeRel
.
getSufId
())
.
getTableId
())
&&
columnCAResult
.
getColumnCASMaps
()
.
get
(
nodeRel2
.
getSufId
())
.
getName
()
.
equals
(
columnCAResult
.
getColumnCASMaps
()
.
get
(
nodeRel
.
getSufId
())
.
getName
())
&&
!
columnCAResult
.
getColumnCASMaps
()
.
get
(
nodeRel2
.
getPreId
())
.
getType
()
.
equals
(
"Data Sink"
))
{
addNodeRels
.
add
(
new
NodeRel
(
nodeRel2
.
getPreId
(),
nodeRel
.
getPreId
()));
}
}
delNodeRels
.
add
(
nodeRel
);
}
}
for
(
NodeRel
nodeRel
:
addNodeRels
)
{
columnCAResult
.
getColumnCASRelChain
().
add
(
nodeRel
);
}
for
(
NodeRel
nodeRel
:
delNodeRels
)
{
columnCAResult
.
getColumnCASRelChain
().
remove
(
nodeRel
);
}
}
}
}
}
}
private
ObjectNode
translateObjectNode
(
String
statement
)
{
return
executor
.
getStreamGraph
(
statement
);
}
private
ObjectNode
translateObjectNode
(
List
<
String
>
statement
)
{
return
executor
.
getStreamGraph
(
statement
);
}
private
List
<
Trans
>
translateTrans
(
ObjectNode
plan
)
{
return
new
TransGenerator
(
plan
).
translateTrans
();
}
public
List
<
LineageRel
>
getLineage
(
String
statement
)
{
public
List
<
LineageRel
>
getLineage
(
String
statement
)
{
JobConfig
jobConfig
=
JobConfig
jobConfig
=
new
JobConfig
(
new
JobConfig
(
...
...
dinky-core/src/main/java/org/dinky/explainer/ca/CABuilder.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
org.dinky.plus.FlinkSqlPlus
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
/**
* CABuilder
*
* @author wenmo
* @since 2021/6/23 11:03
*/
@Deprecated
public
class
CABuilder
{
public
static
List
<
TableCANode
>
getOneTableCAByStatement
(
String
statement
)
{
List
<
TableCANode
>
tableCANodes
=
new
ArrayList
<>();
FlinkSqlPlus
plus
=
FlinkSqlPlus
.
build
();
List
<
TableCAResult
>
results
=
plus
.
generateTableCA
(
statement
);
for
(
int
j
=
0
;
j
<
results
.
size
();
j
++)
{
TableCAResult
result
=
results
.
get
(
j
);
TableCANode
node
=
new
TableCANode
();
TableCA
sinkTableCA
=
(
TableCA
)
result
.
getSinkTableCA
();
node
.
setName
(
sinkTableCA
.
getTableName
());
List
<
TableCANode
>
children
=
new
ArrayList
<>();
for
(
int
k
=
0
;
k
<
result
.
getSourceTableCAS
().
size
();
k
++)
{
children
.
add
(
new
TableCANode
(
result
.
getSourceTableCAS
().
get
(
k
).
getTableName
()));
}
node
.
setChildren
(
children
);
tableCANodes
.
add
(
node
);
}
return
tableCANodes
;
}
public
static
List
<
TableCANode
>
getOneTableColumnCAByStatement
(
String
statement
)
{
List
<
TableCANode
>
tableCANodes
=
new
ArrayList
<>();
FlinkSqlPlus
plus
=
FlinkSqlPlus
.
build
();
int
id
=
1
;
List
<
TableCAResult
>
results
=
plus
.
explainSqlTableColumnCA
(
statement
);
for
(
int
j
=
0
;
j
<
results
.
size
();
j
++)
{
TableCAResult
result
=
results
.
get
(
j
);
TableCA
sinkTableCA
=
(
TableCA
)
result
.
getSinkTableCA
();
TableCANode
node
=
new
TableCANode
(
id
++,
sinkTableCA
.
getTableName
(),
sinkTableCA
.
getFields
());
List
<
TableCANode
>
children
=
new
ArrayList
<>();
for
(
int
k
=
0
;
k
<
result
.
getSourceTableCAS
().
size
();
k
++)
{
TableCA
tableCA
=
(
TableCA
)
result
.
getSourceTableCAS
().
get
(
k
);
children
.
add
(
new
TableCANode
(
id
++,
tableCA
.
getTableName
(),
tableCA
.
getFields
()));
}
node
.
setChildren
(
children
);
tableCANodes
.
add
(
node
);
}
return
tableCANodes
;
}
@Deprecated
public
static
List
<
ColumnCANode
>
getColumnCAByStatement
(
String
statement
)
{
List
<
ColumnCANode
>
columnCANodes
=
new
ArrayList
<>();
FlinkSqlPlus
plus
=
FlinkSqlPlus
.
build
();
List
<
ColumnCAResult
>
columnCAResults
=
plus
.
explainSqlColumnCA
(
statement
);
for
(
int
j
=
0
;
j
<
columnCAResults
.
size
();
j
++)
{
ColumnCAResult
result
=
columnCAResults
.
get
(
j
);
List
<
Integer
>
sinkColumns
=
result
.
getSinkColumns
();
for
(
int
k
=
0
;
k
<
sinkColumns
.
size
();
k
++)
{
ColumnCA
columnCA
=
(
ColumnCA
)
result
.
getColumnCASMaps
().
get
(
sinkColumns
.
get
(
k
));
ColumnCANode
node
=
new
ColumnCANode
();
node
.
setName
(
columnCA
.
getAlias
());
node
.
setType
(
columnCA
.
getType
());
node
.
setTitle
(
columnCA
.
getAlias
());
node
.
setOperation
(
columnCA
.
getOperation
());
List
<
ColumnCANode
>
children
=
new
ArrayList
<>();
buildColumnCANodeChildren
(
children
,
result
,
sinkColumns
.
get
(
k
),
columnCA
.
getOperation
());
node
.
setChildren
(
children
);
columnCANodes
.
add
(
node
);
}
}
return
columnCANodes
;
}
private
static
void
buildColumnCANodeChildren
(
List
<
ColumnCANode
>
children
,
ColumnCAResult
result
,
Integer
columnId
,
String
operation
)
{
Set
<
NodeRel
>
columnCASRel
=
result
.
getColumnCASRel
();
boolean
hasChildren
=
false
;
for
(
NodeRel
nodeRel
:
columnCASRel
)
{
if
(
columnId
.
equals
(
nodeRel
.
getSufId
()))
{
ColumnCA
childca
=
(
ColumnCA
)
result
.
getColumnCASMaps
().
get
(
nodeRel
.
getPreId
());
// operation =
// operation.replaceAll(childca.getAlias().replaceAll("\\$","\\\\$"),childca.getOperation());
operation
=
operation
.
replaceAll
(
childca
.
getAlias
().
replaceAll
(
"\\)"
,
""
),
childca
.
getOperation
());
buildColumnCANodeChildren
(
children
,
result
,
nodeRel
.
getPreId
(),
operation
);
hasChildren
=
true
;
}
}
if
(!
hasChildren
)
{
ColumnCA
columnCA
=
(
ColumnCA
)
result
.
getColumnCASMaps
().
get
(
columnId
);
if
(
result
.
getSourColumns
().
contains
(
columnCA
.
getId
()))
{
ColumnCANode
columnCANode
=
new
ColumnCANode
();
columnCANode
.
setName
(
columnCA
.
getName
());
columnCANode
.
setTitle
(
columnCA
.
getName
());
columnCANode
.
setOperation
(
operation
);
children
.
add
(
columnCANode
);
}
}
}
}
dinky-core/src/main/java/org/dinky/explainer/ca/CAGenerator.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
public
interface
CAGenerator
{
void
translate
();
}
dinky-core/src/main/java/org/dinky/explainer/ca/ColumnCA.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
java.util.List
;
/**
* ColumnCA
*
* @author wenmo
* @since 2021/6/22
*/
public
class
ColumnCA
implements
ICA
{
private
Integer
id
;
private
Integer
tableId
;
private
List
<
Integer
>
parentId
;
private
String
name
;
private
String
alias
;
private
String
operation
;
private
String
columnName
;
private
String
familyName
;
private
String
type
;
private
String
columnType
;
private
TableCA
tableCA
;
private
String
tableName
;
public
ColumnCA
(
Integer
id
,
String
name
,
String
alias
,
String
columnName
,
String
familyName
,
String
operation
,
TableCA
tableCA
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
alias
=
alias
;
this
.
columnName
=
columnName
;
this
.
familyName
=
familyName
;
this
.
operation
=
operation
;
this
.
tableCA
=
tableCA
;
this
.
tableId
=
tableCA
.
getId
();
this
.
tableName
=
tableCA
.
getName
();
this
.
type
=
tableCA
.
getType
();
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
List
<
Integer
>
getParentId
()
{
return
parentId
;
}
public
void
setParentId
(
List
<
Integer
>
parentId
)
{
this
.
parentId
=
parentId
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getAlias
()
{
return
alias
;
}
public
void
setAlias
(
String
alias
)
{
this
.
alias
=
alias
;
}
public
String
getColumnName
()
{
return
columnName
;
}
public
void
setColumnName
(
String
columnName
)
{
this
.
columnName
=
columnName
;
}
public
String
getFamilyName
()
{
return
familyName
;
}
public
void
setFamilyName
(
String
familyName
)
{
this
.
familyName
=
familyName
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
TableCA
getTableCA
()
{
return
tableCA
;
}
public
void
setTableCA
(
TableCA
tableCA
)
{
this
.
tableCA
=
tableCA
;
}
public
Integer
getTableId
()
{
return
tableId
;
}
public
void
setTableId
(
Integer
tableId
)
{
this
.
tableId
=
tableId
;
}
public
String
getColumnType
()
{
return
columnType
;
}
public
void
setColumnType
(
String
columnType
)
{
this
.
columnType
=
columnType
;
}
public
String
getTableName
()
{
return
tableName
;
}
public
void
setTableName
(
String
tableName
)
{
this
.
tableName
=
tableName
;
}
public
String
getOperation
()
{
return
operation
;
}
public
void
setOperation
(
String
operation
)
{
this
.
operation
=
operation
;
}
}
dinky-core/src/main/java/org/dinky/explainer/ca/ColumnCAGenerator.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.explainer.trans.Field
;
import
org.dinky.explainer.trans.OperatorTrans
;
import
org.dinky.explainer.trans.SinkTrans
;
import
org.dinky.explainer.trans.SourceTrans
;
import
org.dinky.explainer.trans.Trans
;
import
org.dinky.utils.MapParseUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* ColumnCAGenerator
*
* @author wenmo
* @since 2021/6/22
*/
@Deprecated
public
class
ColumnCAGenerator
implements
CAGenerator
{
private
List
<
Trans
>
transList
;
private
Map
<
Integer
,
Trans
>
transMaps
;
private
Set
<
Integer
>
parentIdSet
;
private
List
<
ICA
>
sourceTableCAS
=
new
ArrayList
<>();
private
List
<
ICA
>
columnCAS
=
new
ArrayList
<>();
private
Map
<
Integer
,
ICA
>
columnCASMaps
;
private
Set
<
NodeRel
>
columnCASRel
;
private
ICA
sinkTableCA
=
null
;
private
String
sinkTableName
;
private
Integer
index
=
1
;
private
List
<
Integer
>
sinkColumns
;
private
List
<
Integer
>
sourceColumns
;
public
ColumnCAGenerator
(
List
<
Trans
>
transList
)
{
this
.
transList
=
transList
;
this
.
transMaps
=
new
HashMap
<>();
this
.
parentIdSet
=
new
HashSet
<>();
this
.
columnCASMaps
=
new
HashMap
<>();
this
.
columnCASRel
=
new
HashSet
<>();
for
(
int
i
=
0
;
i
<
transList
.
size
();
i
++)
{
this
.
transMaps
.
put
(
transList
.
get
(
i
).
getId
(),
transList
.
get
(
i
));
if
(
transList
.
get
(
i
).
getParentId
()
!=
null
)
{
parentIdSet
.
add
(
transList
.
get
(
i
).
getParentId
());
}
}
}
@Override
public
void
translate
()
{
for
(
int
i
=
0
;
i
<
transList
.
size
();
i
++)
{
if
(
transList
.
get
(
i
)
instanceof
SourceTrans
)
{
TableCA
tableCA
=
new
TableCA
((
SourceTrans
)
transList
.
get
(
i
));
paddingFields
(
tableCA
);
List
<
String
>
sourceFields
=
new
ArrayList
<>();
CollectionUtils
.
addAll
(
sourceFields
,
new
Object
[
tableCA
.
getFields
().
size
()]);
Collections
.
copy
(
sourceFields
,
tableCA
.
getFields
());
for
(
int
j
=
0
;
j
<
sourceFields
.
size
();
j
++)
{
String
fieldName
=
sourceFields
.
get
(
j
);
Integer
id
=
index
++;
ColumnCA
columnCA
=
new
ColumnCA
(
id
,
fieldName
,
fieldName
,
fieldName
,
fieldName
,
fieldName
,
tableCA
);
this
.
columnCASMaps
.
put
(
id
,
columnCA
);
this
.
columnCAS
.
add
(
columnCA
);
}
for
(
int
j
=
0
;
j
<
this
.
columnCAS
.
size
();
j
++)
{
ColumnCA
columnCA
=
(
ColumnCA
)
this
.
columnCAS
.
get
(
j
);
if
(
columnCA
.
getTableCA
().
getId
().
equals
(
tableCA
.
getId
()))
{
buildColumnCAFields
(
tableCA
,
tableCA
.
getParentId
(),
columnCA
);
}
}
}
}
for
(
int
i
=
0
;
i
<
transList
.
size
();
i
++)
{
if
(
transList
.
get
(
i
)
instanceof
SinkTrans
)
{
TableCA
tableCA
=
new
TableCA
((
SinkTrans
)
transList
.
get
(
i
));
searchColumnCAId
(
tableCA
);
this
.
sinkTableCA
=
tableCA
;
this
.
sinkTableName
=
tableCA
.
getName
();
}
}
}
private
void
searchColumnCAId
(
TableCA
tableCA
)
{
List
<
Integer
>
sufOnly
=
new
ArrayList
<>();
for
(
NodeRel
nodeRel
:
this
.
columnCASRel
)
{
if
(!
sufOnly
.
contains
(
nodeRel
.
getSufId
()))
{
sufOnly
.
add
(
nodeRel
.
getSufId
());
}
}
for
(
NodeRel
nodeRel
:
this
.
columnCASRel
)
{
if
(
sufOnly
.
contains
(
nodeRel
.
getPreId
()))
{
sufOnly
.
remove
(
nodeRel
.
getPreId
());
}
}
List
<
Integer
>
preOnly
=
new
ArrayList
<>();
for
(
NodeRel
nodeRel
:
this
.
columnCASRel
)
{
if
(!
preOnly
.
contains
(
nodeRel
.
getPreId
()))
{
preOnly
.
add
(
nodeRel
.
getPreId
());
}
}
for
(
NodeRel
nodeRel
:
this
.
columnCASRel
)
{
if
(
preOnly
.
contains
(
nodeRel
.
getSufId
()))
{
preOnly
.
remove
(
nodeRel
.
getSufId
());
}
}
for
(
int
i
=
0
;
i
<
sufOnly
.
size
();
i
++)
{
ColumnCA
columnCA
=
(
ColumnCA
)
this
.
columnCASMaps
.
get
(
sufOnly
.
get
(
i
));
List
<
String
>
fields
=
tableCA
.
getFields
();
for
(
int
j
=
0
;
j
<
fields
.
size
();
j
++)
{
if
(
columnCA
.
getAlias
().
equals
(
fields
.
get
(
j
)))
{
tableCA
.
getColumnCAIds
().
add
(
sufOnly
.
get
(
i
));
break
;
}
}
}
this
.
sinkColumns
=
sufOnly
;
this
.
sourceColumns
=
preOnly
;
}
private
void
paddingFields
(
TableCA
tableCA
)
{
for
(
int
i
=
0
;
i
<
this
.
sourceTableCAS
.
size
();
i
++)
{
if
(
this
.
sourceTableCAS
.
get
(
i
)
instanceof
TableCA
)
{
TableCA
sourceTableCA
=
(
TableCA
)
this
.
sourceTableCAS
.
get
(
i
);
if
(
sourceTableCA
.
getId
().
equals
(
tableCA
.
getId
()))
{
tableCA
.
setFields
(
sourceTableCA
.
getFields
());
}
}
}
}
private
void
buildColumnCAFields
(
TableCA
tableCA
,
Integer
id
,
ColumnCA
columnCA
)
{
if
(
transMaps
.
get
(
id
)
instanceof
OperatorTrans
)
{
OperatorTrans
trans
=
(
OperatorTrans
)
transMaps
.
get
(
id
);
List
<
Field
>
selects
=
trans
.
getSelect
();
if
(
Asserts
.
isNotNull
(
selects
))
{
for
(
int
i
=
0
;
i
<
selects
.
size
();
i
++)
{
String
operation
=
selects
.
get
(
i
).
getFragment
();
String
alias
=
selects
.
get
(
i
).
getAlias
();
searchSelect
(
tableCA
,
columnCA
,
trans
,
operation
,
alias
);
}
}
if
(
trans
.
getParentId
()
!=
null
)
{
buildColumnCAFields
(
tableCA
,
trans
.
getParentId
(),
columnCA
);
}
}
}
private
void
searchSelect
(
TableCA
tableCA
,
ColumnCA
columnCA
,
OperatorTrans
trans
,
String
operation
,
String
alias
)
{
if
(
MapParseUtils
.
hasField
(
operation
,
columnCA
.
getAlias
()))
{
boolean
isHad
=
false
;
Integer
cid
=
null
;
for
(
int
j
=
0
;
j
<
this
.
columnCAS
.
size
();
j
++)
{
ColumnCA
columnCA1
=
(
ColumnCA
)
this
.
columnCAS
.
get
(
j
);
if
(
columnCA1
.
getTableCA
().
getId
().
equals
(
tableCA
.
getId
())
&&
columnCA1
.
getName
().
equals
(
alias
))
{
isHad
=
true
;
cid
=
columnCA1
.
getId
();
break
;
}
}
if
(!
isHad
)
{
cid
=
index
++;
// String columnOperation =
// MapParseUtils.replaceField(operation,columnCA.getAlias(),columnCA.getOperation());
ColumnCA
columnCA2
=
new
ColumnCA
(
cid
,
alias
,
alias
,
alias
,
alias
,
operation
,
tableCA
);
this
.
columnCASMaps
.
put
(
cid
,
columnCA2
);
this
.
columnCAS
.
add
(
columnCA2
);
buildColumnCAFields
(
tableCA
,
trans
.
getParentId
(),
columnCA2
);
}
this
.
columnCASRel
.
add
(
new
NodeRel
(
columnCA
.
getId
(),
cid
));
}
}
public
List
<
Trans
>
getTransList
()
{
return
transList
;
}
public
void
setTransList
(
List
<
Trans
>
transList
)
{
this
.
transList
=
transList
;
}
public
Map
<
Integer
,
Trans
>
getTransMaps
()
{
return
transMaps
;
}
public
void
setTransMaps
(
Map
<
Integer
,
Trans
>
transMaps
)
{
this
.
transMaps
=
transMaps
;
}
public
Set
<
Integer
>
getParentIdSet
()
{
return
parentIdSet
;
}
public
void
setParentIdSet
(
Set
<
Integer
>
parentIdSet
)
{
this
.
parentIdSet
=
parentIdSet
;
}
public
List
<
ICA
>
getSourceTableCAS
()
{
return
sourceTableCAS
;
}
public
void
setSourceTableCAS
(
List
<
ICA
>
sourceTableCAS
)
{
this
.
sourceTableCAS
=
sourceTableCAS
;
}
public
List
<
ICA
>
getColumnCAS
()
{
return
columnCAS
;
}
public
void
setColumnCAS
(
List
<
ICA
>
columnCAS
)
{
this
.
columnCAS
=
columnCAS
;
}
public
ICA
getSinkTableCA
()
{
return
sinkTableCA
;
}
public
void
setSinkTableCA
(
ICA
sinkTableCA
)
{
this
.
sinkTableCA
=
sinkTableCA
;
}
public
String
getSinkTableName
()
{
return
sinkTableName
;
}
public
void
setSinkTableName
(
String
sinkTableName
)
{
this
.
sinkTableName
=
sinkTableName
;
}
public
Map
<
Integer
,
ICA
>
getColumnCASMaps
()
{
return
columnCASMaps
;
}
public
void
setColumnCASMaps
(
Map
<
Integer
,
ICA
>
columnCASMaps
)
{
this
.
columnCASMaps
=
columnCASMaps
;
}
public
Set
<
NodeRel
>
getColumnCASRel
()
{
return
columnCASRel
;
}
public
void
setColumnCASRel
(
Set
<
NodeRel
>
columnCASRel
)
{
this
.
columnCASRel
=
columnCASRel
;
}
public
List
<
Integer
>
getSinkColumns
()
{
return
sinkColumns
;
}
public
void
setSinkColumns
(
List
<
Integer
>
sinkColumns
)
{
this
.
sinkColumns
=
sinkColumns
;
}
public
List
<
Integer
>
getSourceColumns
()
{
return
sourceColumns
;
}
public
void
setSourceColumns
(
List
<
Integer
>
sourceColumns
)
{
this
.
sourceColumns
=
sourceColumns
;
}
}
dinky-core/src/main/java/org/dinky/explainer/ca/ColumnCANode.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
java.io.Serializable
;
import
java.util.List
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* ColumnCANode
*
* @author wenmo
* @since 2021/6/23 11:03
*/
@Getter
@Setter
public
class
ColumnCANode
implements
Serializable
{
private
static
final
long
serialVersionUID
=
122624200268430762L
;
private
Integer
id
;
private
Integer
tableId
;
private
String
name
;
private
String
title
;
private
String
value
;
private
String
type
;
private
String
operation
;
private
List
<
ColumnCANode
>
children
;
public
ColumnCANode
()
{}
}
dinky-core/src/main/java/org/dinky/explainer/ca/ColumnCAResult.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
org.dinky.explainer.lineage.LineageColumnGenerator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* ColumnCAResult
*
* @author wenmo
* @since 2021/6/22
*/
public
class
ColumnCAResult
{
private
List
<
TableCA
>
tableCAS
;
private
Map
<
Integer
,
ColumnCA
>
columnCASMaps
;
private
Set
<
NodeRel
>
columnCASRel
;
private
Set
<
NodeRel
>
columnCASRelChain
;
private
List
<
Integer
>
sinkColumns
;
private
List
<
Integer
>
sourColumns
;
public
ColumnCAResult
(
LineageColumnGenerator
generator
)
{
this
.
tableCAS
=
generator
.
getTableCAS
();
this
.
columnCASMaps
=
generator
.
getColumnCASMaps
();
this
.
columnCASRel
=
generator
.
getColumnCASRel
();
this
.
columnCASRelChain
=
generator
.
getColumnCASRelChain
();
this
.
sinkColumns
=
generator
.
getSinkColumns
();
this
.
sourColumns
=
generator
.
getSourceColumns
();
}
public
List
<
TableCA
>
getTableCAS
()
{
return
tableCAS
;
}
public
void
setTableCAS
(
List
<
TableCA
>
tableCAS
)
{
this
.
tableCAS
=
tableCAS
;
}
public
Map
<
Integer
,
ColumnCA
>
getColumnCASMaps
()
{
return
columnCASMaps
;
}
public
void
setColumnCASMaps
(
Map
<
Integer
,
ColumnCA
>
columnCASMaps
)
{
this
.
columnCASMaps
=
columnCASMaps
;
}
public
Set
<
NodeRel
>
getColumnCASRel
()
{
return
columnCASRel
;
}
public
void
setColumnCASRel
(
Set
<
NodeRel
>
columnCASRel
)
{
this
.
columnCASRel
=
columnCASRel
;
}
public
Set
<
NodeRel
>
getColumnCASRelChain
()
{
return
columnCASRelChain
;
}
public
void
setColumnCASRelChain
(
Set
<
NodeRel
>
columnCASRelChain
)
{
this
.
columnCASRelChain
=
columnCASRelChain
;
}
public
List
<
Integer
>
getSinkColumns
()
{
return
sinkColumns
;
}
public
void
setSinkColumns
(
List
<
Integer
>
sinkColumns
)
{
this
.
sinkColumns
=
sinkColumns
;
}
public
List
<
Integer
>
getSourColumns
()
{
return
sourColumns
;
}
public
void
setSourColumns
(
List
<
Integer
>
sourColumns
)
{
this
.
sourColumns
=
sourColumns
;
}
}
dinky-core/src/main/java/org/dinky/explainer/ca/ICA.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
public
interface
ICA
{
Integer
getId
();
String
getTableName
();
}
dinky-core/src/main/java/org/dinky/explainer/ca/NodeRel.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
java.util.Objects
;
/**
* NodeRel
*
* @author wenmo
* @since 2021/6/22
*/
public
class
NodeRel
{
private
Integer
preId
;
private
Integer
sufId
;
public
NodeRel
(
Integer
preId
,
Integer
sufId
)
{
this
.
preId
=
preId
;
this
.
sufId
=
sufId
;
}
public
Integer
getPreId
()
{
return
preId
;
}
public
void
setPreId
(
Integer
preId
)
{
this
.
preId
=
preId
;
}
public
Integer
getSufId
()
{
return
sufId
;
}
public
void
setSufId
(
Integer
sufId
)
{
this
.
sufId
=
sufId
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
NodeRel
nodeRel
=
(
NodeRel
)
o
;
return
Objects
.
equals
(
preId
,
nodeRel
.
preId
)
&&
Objects
.
equals
(
sufId
,
nodeRel
.
sufId
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
preId
,
sufId
);
}
}
dinky-core/src/main/java/org/dinky/explainer/ca/TableCA.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.explainer.trans.Field
;
import
org.dinky.explainer.trans.OperatorTrans
;
import
org.dinky.explainer.trans.SinkTrans
;
import
org.dinky.explainer.trans.SourceTrans
;
import
org.dinky.explainer.trans.Trans
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* TableCA
*
* @author wenmo
* @since 2021/6/22
*/
@Getter
@Setter
public
class
TableCA
implements
ICA
{
private
Integer
id
;
private
Integer
parentId
;
private
String
name
;
private
String
catalog
;
private
String
database
;
private
String
table
;
private
String
type
;
private
List
<
String
>
fields
;
private
List
<
String
>
useFields
;
private
List
<
String
>
alias
;
private
Set
<
Integer
>
columnCAIds
=
new
HashSet
<>();
private
Integer
parallelism
;
private
static
final
TableCA
EMPTY
=
new
TableCA
();
public
TableCA
()
{}
public
TableCA
(
SourceTrans
trans
)
{
this
.
id
=
trans
.
getId
();
this
.
parentId
=
trans
.
getParentId
();
this
.
name
=
trans
.
getName
();
this
.
catalog
=
trans
.
getCatalog
();
this
.
database
=
trans
.
getDatabase
();
this
.
table
=
trans
.
getTable
();
this
.
fields
=
trans
.
getFields
();
this
.
useFields
=
trans
.
getFields
();
this
.
parallelism
=
trans
.
getParallelism
();
this
.
type
=
trans
.
getPact
();
}
public
TableCA
(
SinkTrans
trans
)
{
this
.
id
=
trans
.
getId
();
this
.
parentId
=
trans
.
getParentId
();
this
.
name
=
trans
.
getName
();
this
.
catalog
=
trans
.
getCatalog
();
this
.
database
=
trans
.
getDatabase
();
this
.
table
=
trans
.
getTable
();
this
.
fields
=
trans
.
getFields
();
this
.
useFields
=
trans
.
getFields
();
this
.
parallelism
=
trans
.
getParallelism
();
this
.
type
=
trans
.
getPact
();
}
public
TableCA
(
OperatorTrans
trans
)
{
List
<
String
>
tableList
=
trans
.
getTable
();
this
.
id
=
trans
.
getId
();
this
.
parentId
=
trans
.
getParentId
();
List
<
Field
>
select
=
trans
.
getSelect
();
List
<
String
>
fieldList
=
new
ArrayList
<>();
for
(
Field
field
:
select
)
{
fieldList
.
add
(
field
.
getAlias
());
}
this
.
fields
=
fieldList
;
this
.
useFields
=
fieldList
;
this
.
parallelism
=
trans
.
getParallelism
();
this
.
type
=
trans
.
getPact
();
if
(
tableList
.
size
()
>
0
)
{
String
tableStr
=
tableList
.
get
(
0
);
String
[]
strings
=
tableStr
.
split
(
"\\."
);
if
(
strings
.
length
>
2
)
{
this
.
catalog
=
strings
[
0
];
this
.
database
=
strings
[
1
];
this
.
table
=
strings
[
2
];
}
else
if
(
strings
.
length
==
2
)
{
this
.
catalog
=
"default_catalog"
;
this
.
database
=
strings
[
0
];
this
.
table
=
strings
[
1
];
}
else
if
(
strings
.
length
==
1
)
{
this
.
catalog
=
"default_catalog"
;
this
.
database
=
"default_database"
;
this
.
table
=
strings
[
0
];
}
}
this
.
name
=
this
.
catalog
+
"."
+
this
.
database
+
"."
+
this
.
table
;
}
public
static
TableCA
build
(
Trans
trans
)
{
if
(
trans
instanceof
SourceTrans
)
{
return
new
TableCA
((
SourceTrans
)
trans
);
}
else
if
(
trans
instanceof
SinkTrans
)
{
return
new
TableCA
((
SinkTrans
)
trans
);
}
else
if
(
trans
instanceof
OperatorTrans
)
{
OperatorTrans
operatorTrans
=
(
OperatorTrans
)
trans
;
if
(
Asserts
.
isNotNullCollection
(
operatorTrans
.
getTable
()))
{
return
new
TableCA
(
operatorTrans
);
}
else
{
return
null
;
}
}
else
{
return
null
;
}
}
@Override
public
String
toString
()
{
return
"TableCA{"
+
"id="
+
id
+
", parentId="
+
parentId
+
", name='"
+
name
+
'\''
+
", catalog='"
+
catalog
+
'\''
+
", database='"
+
database
+
'\''
+
", table='"
+
table
+
'\''
+
", fields="
+
fields
+
", useFields="
+
useFields
+
", parallelism="
+
parallelism
+
'}'
;
}
@Override
public
String
getTableName
()
{
return
this
.
table
;
}
}
dinky-core/src/main/java/org/dinky/explainer/ca/TableCAGenerator.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.explainer.trans.Field
;
import
org.dinky.explainer.trans.OperatorTrans
;
import
org.dinky.explainer.trans.SinkTrans
;
import
org.dinky.explainer.trans.SourceTrans
;
import
org.dinky.explainer.trans.Trans
;
import
org.apache.commons.collections.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* TableCAGenerator
*
* @author wenmo
* @since 2021/6/22
*/
public
class
TableCAGenerator
implements
CAGenerator
{
private
List
<
Trans
>
transList
;
private
Map
<
Integer
,
Trans
>
transMaps
;
private
Set
<
Integer
>
parentIdSet
;
private
List
<
ICA
>
sourceTableCAS
=
new
ArrayList
<>();
private
List
<
ICA
>
sinkTableCAS
=
new
ArrayList
<>();
private
ICA
sinkTableCA
=
null
;
private
String
sinkTableName
;
public
TableCAGenerator
(
List
<
Trans
>
transList
)
{
this
.
transList
=
transList
;
this
.
transMaps
=
new
HashMap
<>();
this
.
parentIdSet
=
new
HashSet
<>();
for
(
int
i
=
0
;
i
<
transList
.
size
();
i
++)
{
this
.
transMaps
.
put
(
transList
.
get
(
i
).
getId
(),
transList
.
get
(
i
));
if
(
transList
.
get
(
i
).
getParentId
()
!=
null
)
{
parentIdSet
.
add
(
transList
.
get
(
i
).
getParentId
());
}
}
}
public
static
TableCAGenerator
build
(
List
<
Trans
>
transList
)
{
return
new
TableCAGenerator
(
transList
);
}
public
TableCAResult
getResult
()
{
return
new
TableCAResult
(
this
);
}
@Override
public
void
translate
()
{
for
(
Trans
trans
:
transList
)
{
if
(
trans
instanceof
SourceTrans
)
{
TableCA
tableCA
=
TableCA
.
build
(
trans
);
List
<
String
>
sourceFields
=
new
ArrayList
<>();
CollectionUtils
.
addAll
(
sourceFields
,
new
Object
[
tableCA
.
getFields
().
size
()]);
Collections
.
copy
(
sourceFields
,
tableCA
.
getFields
());
for
(
int
j
=
0
;
j
<
sourceFields
.
size
();
j
++)
{
buildTableCAFields
(
tableCA
,
tableCA
.
getParentId
(),
sourceFields
.
get
(
j
));
}
this
.
sourceTableCAS
.
add
(
tableCA
);
}
else
if
(
trans
instanceof
SinkTrans
)
{
TableCA
tableCA
=
TableCA
.
build
(
trans
);
this
.
sinkTableCA
=
tableCA
;
this
.
sinkTableName
=
tableCA
.
getName
();
this
.
sinkTableCAS
.
add
(
TableCA
.
build
(
trans
));
}
}
}
public
void
translateOnlyTable
()
{
for
(
Trans
trans
:
transList
)
{
if
(
trans
instanceof
SourceTrans
)
{
this
.
sourceTableCAS
.
add
(
new
TableCA
((
SourceTrans
)
trans
));
}
else
if
(
trans
instanceof
SinkTrans
)
{
TableCA
tableCA
=
new
TableCA
((
SinkTrans
)
trans
);
this
.
sinkTableCA
=
tableCA
;
this
.
sinkTableName
=
tableCA
.
getName
();
}
}
}
private
void
buildTableCAFields
(
TableCA
tableCA
,
Integer
id
,
String
field
)
{
if
(
transMaps
.
get
(
id
)
instanceof
OperatorTrans
)
{
OperatorTrans
trans
=
(
OperatorTrans
)
transMaps
.
get
(
id
);
searchSelectFields
(
tableCA
,
trans
.
getSelect
(),
field
);
searchWhereFields
(
tableCA
,
trans
.
getWhere
(),
field
);
if
(
Asserts
.
isNotNull
(
trans
.
getParentId
()))
{
buildTableCAFields
(
tableCA
,
trans
.
getParentId
(),
field
);
}
}
}
private
void
searchSelectFields
(
TableCA
tableCA
,
List
<
Field
>
selects
,
String
field
)
{
if
(
Asserts
.
isNotNull
(
selects
))
{
for
(
int
i
=
0
;
i
<
selects
.
size
();
i
++)
{
List
<
String
>
fields
=
matchFields
(
selects
.
get
(
i
).
getFragment
(),
field
);
/*
* if(tableCA.getFields().contains(field)){ tableCA.getFields().remove(field); }
*/
for
(
int
j
=
0
;
j
<
fields
.
size
();
j
++)
{
if
(!
tableCA
.
getUseFields
().
contains
(
fields
.
get
(
j
)))
{
tableCA
.
getUseFields
().
add
(
fields
.
get
(
j
));
}
}
}
}
}
private
void
searchWhereFields
(
TableCA
tableCA
,
String
wheres
,
String
field
)
{
if
(
Asserts
.
isNotNull
(
wheres
)
&&
!
"[]"
.
equals
(
wheres
))
{
List
<
String
>
fields
=
matchFields
(
wheres
,
field
);
/*
* if(tableCA.getFields().contains(field)){ tableCA.getFields().remove(field); }
*/
for
(
int
j
=
0
;
j
<
fields
.
size
();
j
++)
{
if
(!
tableCA
.
getUseFields
().
contains
(
fields
.
get
(
j
)))
{
tableCA
.
getUseFields
().
add
(
fields
.
get
(
j
));
}
}
}
}
private
List
<
String
>
matchFields
(
String
fragement
,
String
field
)
{
List
<
String
>
fields
=
new
ArrayList
<>();
String
sign
=
"([^a-zA-Z0-9_]?)"
;
Pattern
p
=
Pattern
.
compile
(
sign
+
field
+
sign
);
Matcher
m
=
p
.
matcher
(
fragement
);
while
(
m
.
find
())
{
fields
.
add
(
m
.
group
(
1
).
trim
());
fields
.
add
(
fragement
.
trim
());
}
if
(
fragement
.
equals
(
field
))
{
fields
.
add
(
fragement
.
trim
());
}
return
fields
;
}
public
List
<
Trans
>
getTransList
()
{
return
transList
;
}
public
Map
<
Integer
,
Trans
>
getTransMaps
()
{
return
transMaps
;
}
public
Set
<
Integer
>
getParentIdSet
()
{
return
parentIdSet
;
}
public
List
<
ICA
>
getSourceTableCAS
()
{
return
sourceTableCAS
;
}
public
ICA
getSinkTableCA
()
{
return
sinkTableCA
;
}
public
String
getSinkTableName
()
{
return
sinkTableName
;
}
}
dinky-core/src/main/java/org/dinky/explainer/ca/TableCANode.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
java.io.Serializable
;
import
java.util.List
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* TableCANode
*
* @author wenmo
* @since 2021/6/23 11:03
*/
@Getter
@Setter
public
class
TableCANode
implements
Serializable
{
private
static
final
long
serialVersionUID
=
356665302973181483L
;
private
String
id
;
private
Integer
tableId
;
private
String
name
;
private
String
title
;
private
String
value
;
private
String
type
;
private
Integer
columnSize
;
// private Tables tables;
private
List
<
String
>
columns
;
private
List
<
TableCANode
>
children
;
public
TableCANode
()
{}
public
TableCANode
(
String
name
)
{
this
.
name
=
name
;
}
public
TableCANode
(
String
name
,
String
value
)
{
this
.
name
=
name
;
this
.
value
=
value
;
}
public
TableCANode
(
Integer
id
,
String
name
,
List
<
String
>
columns
)
{
this
.
id
=
id
.
toString
();
this
.
name
=
name
;
this
.
title
=
name
;
this
.
columnSize
=
columns
.
size
();
this
.
columns
=
columns
;
}
}
dinky-core/src/main/java/org/dinky/explainer/ca/TableCAResult.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
ca
;
import
java.util.List
;
/**
* TableCAResult
*
* @author wenmo
* @since 2021/6/22
*/
public
class
TableCAResult
{
private
String
sinkName
;
private
List
<
ICA
>
sourceTableCAS
;
private
ICA
sinkTableCA
;
public
TableCAResult
(
TableCAGenerator
generator
)
{
this
.
sourceTableCAS
=
generator
.
getSourceTableCAS
();
this
.
sinkTableCA
=
generator
.
getSinkTableCA
();
this
.
sinkName
=
generator
.
getSinkTableName
();
}
public
String
getSinkName
()
{
return
sinkName
;
}
public
void
setSinkName
(
String
sinkName
)
{
this
.
sinkName
=
sinkName
;
}
public
List
<
ICA
>
getSourceTableCAS
()
{
return
sourceTableCAS
;
}
public
void
setSourceTableCAS
(
List
<
ICA
>
sourceTableCAS
)
{
this
.
sourceTableCAS
=
sourceTableCAS
;
}
public
ICA
getSinkTableCA
()
{
return
sinkTableCA
;
}
public
void
setSinkTableCA
(
ICA
sinkTableCA
)
{
this
.
sinkTableCA
=
sinkTableCA
;
}
}
dinky-core/src/main/java/org/dinky/explainer/lineage/LineageBuilder.java
View file @
e6aeea73
...
@@ -19,18 +19,14 @@
...
@@ -19,18 +19,14 @@
package
org
.
dinky
.
explainer
.
lineage
;
package
org
.
dinky
.
explainer
.
lineage
;
import
org.dinky.explainer.ca.ColumnCAResult
;
import
org.dinky.executor.Executor
;
import
org.dinky.explainer.ca.NodeRel
;
import
org.dinky.explainer.Explainer
;
import
org.dinky.explainer.ca.TableCA
;
import
org.dinky.model.LineageRel
;
import
org.dinky.model.LineageRel
;
import
org.dinky.plus.FlinkSqlPlus
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
/**
/**
* LineageBuilder
* LineageBuilder
...
@@ -40,117 +36,9 @@ import java.util.Set;
...
@@ -40,117 +36,9 @@ import java.util.Set;
*/
*/
public
class
LineageBuilder
{
public
class
LineageBuilder
{
@Deprecated
public
static
LineageResult
getLineage
(
String
statement
)
{
return
getLineage
(
statement
,
true
);
}
@Deprecated
public
static
LineageResult
getLineage
(
String
statement
,
boolean
statementSet
)
{
FlinkSqlPlus
plus
=
FlinkSqlPlus
.
build
(
statementSet
);
List
<
ColumnCAResult
>
columnCAResults
=
plus
.
explainSqlColumnCA
(
statement
);
List
<
LineageTable
>
tables
=
new
ArrayList
<>();
List
<
LineageRelation
>
relations
=
new
ArrayList
<>();
int
index
=
0
;
for
(
ColumnCAResult
item
:
columnCAResults
)
{
for
(
TableCA
tableCA
:
item
.
getTableCAS
())
{
tables
.
add
(
LineageTable
.
build
(
tableCA
));
}
Set
<
String
>
keySet
=
new
HashSet
<>();
for
(
NodeRel
nodeRel
:
item
.
getColumnCASRelChain
())
{
if
(
item
.
getColumnCASMaps
().
containsKey
(
nodeRel
.
getPreId
())
&&
item
.
getColumnCASMaps
().
containsKey
(
nodeRel
.
getSufId
())
&&
!
item
.
getColumnCASMaps
()
.
get
(
nodeRel
.
getPreId
())
.
getTableId
()
.
equals
(
item
.
getColumnCASMaps
()
.
get
(
nodeRel
.
getSufId
())
.
getTableId
()))
{
String
key
=
item
.
getColumnCASMaps
().
get
(
nodeRel
.
getPreId
()).
getTableId
().
toString
()
+
"@"
+
item
.
getColumnCASMaps
()
.
get
(
nodeRel
.
getSufId
())
.
getTableId
()
.
toString
()
+
"@"
+
item
.
getColumnCASMaps
().
get
(
nodeRel
.
getPreId
()).
getName
()
+
"@"
+
item
.
getColumnCASMaps
().
get
(
nodeRel
.
getSufId
()).
getName
();
// 去重
if
(!
keySet
.
contains
(
key
))
{
index
++;
relations
.
add
(
LineageRelation
.
build
(
index
+
""
,
item
.
getColumnCASMaps
()
.
get
(
nodeRel
.
getPreId
())
.
getTableId
()
.
toString
(),
item
.
getColumnCASMaps
()
.
get
(
nodeRel
.
getSufId
())
.
getTableId
()
.
toString
(),
item
.
getColumnCASMaps
().
get
(
nodeRel
.
getPreId
()).
getName
(),
item
.
getColumnCASMaps
().
get
(
nodeRel
.
getSufId
()).
getName
()));
keySet
.
add
(
key
);
}
}
}
}
// 获取重复表集合
List
<
List
<
LineageTable
>>
repeatTablesList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
tables
.
size
()
-
1
;
i
++)
{
List
<
LineageTable
>
repeatTables
=
new
ArrayList
<>();
for
(
int
j
=
i
+
1
;
j
<
tables
.
size
();
j
++)
{
if
(
tables
.
get
(
i
).
getName
().
equals
(
tables
.
get
(
j
).
getName
()))
{
repeatTables
.
add
(
tables
.
get
(
j
));
}
}
if
(
repeatTables
.
size
()
>
0
)
{
repeatTables
.
add
(
tables
.
get
(
i
));
repeatTablesList
.
add
(
repeatTables
);
}
}
// 重复表合并
Map
<
String
,
String
>
correctTableIdMap
=
new
HashMap
<>();
for
(
List
<
LineageTable
>
tableList
:
repeatTablesList
)
{
LineageTable
newTable
=
new
LineageTable
();
Set
<
String
>
columnKeySet
=
new
HashSet
<>();
for
(
LineageTable
table
:
tableList
)
{
if
(
newTable
.
getId
()
==
null
||
newTable
.
getName
()
==
null
)
{
newTable
.
setId
(
table
.
getId
());
newTable
.
setName
(
table
.
getName
());
newTable
.
setColumns
(
new
ArrayList
<>());
}
for
(
LineageColumn
column
:
table
.
getColumns
())
{
String
key
=
column
.
getName
()
+
"@&"
+
column
.
getTitle
();
if
(!
columnKeySet
.
contains
(
key
))
{
newTable
.
getColumns
().
add
(
column
);
columnKeySet
.
add
(
key
);
}
}
correctTableIdMap
.
put
(
table
.
getId
(),
newTable
.
getId
());
tables
.
remove
(
table
);
}
tables
.
add
(
newTable
);
}
// 关系中id重新指向
for
(
LineageRelation
relation
:
relations
)
{
if
(
correctTableIdMap
.
containsKey
(
relation
.
getSrcTableId
()))
{
relation
.
setSrcTableId
(
correctTableIdMap
.
get
(
relation
.
getSrcTableId
()));
}
if
(
correctTableIdMap
.
containsKey
(
relation
.
getTgtTableId
()))
{
relation
.
setTgtTableId
(
correctTableIdMap
.
get
(
relation
.
getTgtTableId
()));
}
}
return
LineageResult
.
build
(
tables
,
relations
);
}
public
static
LineageResult
getColumnLineageByLogicalPlan
(
String
statement
)
{
public
static
LineageResult
getColumnLineageByLogicalPlan
(
String
statement
)
{
FlinkSqlPlus
plus
=
FlinkSqlPlus
.
build
(
false
);
Explainer
explainer
=
new
Explainer
(
Executor
.
build
(),
false
);
List
<
LineageRel
>
lineageRelList
=
plus
.
getLineage
(
statement
);
List
<
LineageRel
>
lineageRelList
=
explainer
.
getLineage
(
statement
);
List
<
LineageRelation
>
relations
=
new
ArrayList
<>();
List
<
LineageRelation
>
relations
=
new
ArrayList
<>();
Map
<
String
,
LineageTable
>
tableMap
=
new
HashMap
<>();
Map
<
String
,
LineageTable
>
tableMap
=
new
HashMap
<>();
int
tableIndex
=
1
;
int
tableIndex
=
1
;
...
...
dinky-core/src/main/java/org/dinky/explainer/lineage/LineageColumnGenerator.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
lineage
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.explainer.ca.ColumnCA
;
import
org.dinky.explainer.ca.NodeRel
;
import
org.dinky.explainer.ca.TableCA
;
import
org.dinky.explainer.trans.Field
;
import
org.dinky.explainer.trans.OperatorTrans
;
import
org.dinky.explainer.trans.Predecessor
;
import
org.dinky.explainer.trans.SinkTrans
;
import
org.dinky.explainer.trans.Trans
;
import
org.dinky.utils.MapParseUtils
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* LineageColumnGenerator
*
* @author wenmo
* @since 2022/3/16 20:20
*/
public
class
LineageColumnGenerator
{
private
Map
<
Integer
,
Trans
>
transMaps
;
private
List
<
TableCA
>
tableCAS
=
new
ArrayList
<>();
private
List
<
ColumnCA
>
columnCAS
=
new
ArrayList
<>();
private
Map
<
Integer
,
ColumnCA
>
columnCASMaps
=
new
HashMap
<>();
private
Set
<
NodeRel
>
columnCASRel
=
new
HashSet
<>();
private
Set
<
NodeRel
>
columnCASRelChain
=
new
HashSet
<>();
private
int
index
=
1
;
private
List
<
Integer
>
sinkColumns
=
new
ArrayList
<>();
private
List
<
Integer
>
sourceColumns
=
new
ArrayList
<>();
public
static
LineageColumnGenerator
build
(
List
<
Trans
>
transList
)
{
LineageColumnGenerator
generator
=
new
LineageColumnGenerator
();
Map
<
Integer
,
Trans
>
map
=
new
HashMap
<>();
for
(
Trans
trans
:
transList
)
{
map
.
put
(
trans
.
getId
(),
trans
);
}
generator
.
setTransMaps
(
map
);
return
generator
;
}
public
void
translate
()
{
for
(
TableCA
tableCA
:
tableCAS
)
{
for
(
String
fieldName
:
tableCA
.
getFields
())
{
int
id
=
index
++;
ColumnCA
columnCA
=
new
ColumnCA
(
id
,
fieldName
,
fieldName
,
fieldName
,
fieldName
,
fieldName
,
tableCA
);
columnCASMaps
.
put
(
id
,
columnCA
);
columnCAS
.
add
(
columnCA
);
buildColumnCAFields
(
tableCA
,
tableCA
.
getParentId
(),
tableCA
.
getId
(),
columnCA
,
new
ArrayList
<>());
}
/*
* for (ColumnCA columnCA : columnCAS) { if (columnCA.getTableCA().getId() == tableCA.getId()) {
* buildColumnCAFields(tableCA, tableCA.getParentId(), tableCA.getId() columnCA, new ArrayList<>()); } }
*/
}
for
(
Map
.
Entry
<
Integer
,
Trans
>
entry
:
transMaps
.
entrySet
())
{
Trans
trans
=
entry
.
getValue
();
if
(
trans
instanceof
SinkTrans
)
{
TableCA
tableCA
=
new
TableCA
((
SinkTrans
)
trans
);
matchSinkField
(
tableCA
);
searchColumnCAId
(
tableCA
);
}
}
chainRelation
();
}
private
void
matchSinkField
(
TableCA
tableCA
)
{
for
(
ColumnCA
columnCA
:
columnCAS
)
{
if
(
columnCA
.
getTableId
().
equals
(
tableCA
.
getId
()))
{
continue
;
}
for
(
String
fieldName
:
tableCA
.
getFields
())
{
if
(
columnCA
.
getName
().
equals
(
fieldName
))
{
int
cid
=
index
++;
ColumnCA
sinkColumnCA
=
new
ColumnCA
(
cid
,
fieldName
,
fieldName
,
fieldName
,
fieldName
,
fieldName
,
tableCA
);
columnCASMaps
.
put
(
cid
,
sinkColumnCA
);
columnCASRel
.
add
(
new
NodeRel
(
columnCA
.
getId
(),
cid
));
}
}
}
}
private
void
buildColumnCAFields
(
TableCA
tableCA
,
Integer
id
,
Integer
preId
,
ColumnCA
columnCA
,
List
<
Field
>
ignoreSelects
)
{
if
(
transMaps
.
get
(
id
)
instanceof
OperatorTrans
)
{
if
(
tableCA
.
getId
().
equals
(
id
))
{
return
;
}
OperatorTrans
trans
=
(
OperatorTrans
)
transMaps
.
get
(
id
);
List
<
Field
>
selects
=
trans
.
getSelect
();
List
<
Field
>
targetSelects
=
new
ArrayList
<>();
if
(
trans
.
getPredecessors
().
size
()
>
1
)
{
int
predecessorsIndex
=
0
;
for
(
Predecessor
predecessor
:
trans
.
getPredecessors
())
{
if
(!
predecessor
.
getId
().
equals
(
preId
))
{
predecessorsIndex
=
predecessorsIndex
+
1
;
}
else
{
break
;
}
}
if
(
predecessorsIndex
==
0
)
{
for
(
int
i
=
0
;
i
<
selects
.
size
();
i
++)
{
if
(
tableCA
.
getUseFields
().
contains
(
selects
.
get
(
i
).
getAlias
()))
{
if
(
targetSelects
.
size
()
==
0
)
{
targetSelects
.
add
(
selects
.
get
(
i
));
}
else
if
(
tableCA
.
getUseFields
()
.
indexOf
(
targetSelects
.
get
(
targetSelects
.
size
()
-
1
)
.
getAlias
())
<
tableCA
.
getUseFields
().
indexOf
(
selects
.
get
(
i
).
getAlias
()))
{
targetSelects
.
add
(
selects
.
get
(
i
));
}
else
{
break
;
}
}
else
{
break
;
}
}
}
else
{
for
(
int
i
=
selects
.
size
()
-
1
;
i
>=
0
;
i
--)
{
if
(
tableCA
.
getUseFields
().
contains
(
selects
.
get
(
i
).
getAlias
()))
{
if
(
targetSelects
.
size
()
==
0
)
{
targetSelects
.
add
(
selects
.
get
(
i
));
}
else
if
(
tableCA
.
getUseFields
()
.
indexOf
(
targetSelects
.
get
(
targetSelects
.
size
()
-
1
)
.
getAlias
())
>
tableCA
.
getUseFields
().
indexOf
(
selects
.
get
(
i
).
getAlias
()))
{
targetSelects
.
add
(
selects
.
get
(
i
));
}
else
{
break
;
}
}
else
{
break
;
}
}
}
}
else
{
if
(
Asserts
.
isNotNullCollection
(
trans
.
getTable
()))
{
for
(
int
i
=
0
;
i
<
selects
.
size
();
i
++)
{
if
(
tableCA
.
getUseFields
().
contains
(
selects
.
get
(
i
).
getAlias
()))
{
if
(
targetSelects
.
size
()
==
0
)
{
targetSelects
.
add
(
selects
.
get
(
i
));
}
else
if
(
tableCA
.
getUseFields
()
.
indexOf
(
targetSelects
.
get
(
targetSelects
.
size
()
-
1
)
.
getAlias
())
<
tableCA
.
getUseFields
().
indexOf
(
selects
.
get
(
i
).
getAlias
()))
{
targetSelects
.
add
(
selects
.
get
(
i
));
}
else
{
break
;
}
}
else
{
break
;
}
}
}
else
{
targetSelects
=
selects
;
}
}
if
(
Asserts
.
isNotNull
(
targetSelects
))
{
if
(
selects
.
size
()
!=
targetSelects
.
size
())
{
for
(
int
i
=
0
;
i
<
selects
.
size
();
i
++)
{
if
(!
targetSelects
.
contains
(
selects
.
get
(
i
)))
{
ignoreSelects
.
add
(
selects
.
get
(
i
));
}
}
}
for
(
int
i
=
0
;
i
<
targetSelects
.
size
();
i
++)
{
String
operation
=
targetSelects
.
get
(
i
).
getFragment
();
String
alias
=
targetSelects
.
get
(
i
).
getAlias
();
searchSelect
(
tableCA
,
columnCA
,
trans
,
operation
,
alias
,
ignoreSelects
);
}
}
List
<
String
>
fields
=
trans
.
getFields
();
if
(
Asserts
.
isNotNull
(
fields
))
{
for
(
int
i
=
0
;
i
<
fields
.
size
();
i
++)
{
String
field
=
fields
.
get
(
i
);
searchSelect
(
tableCA
,
columnCA
,
trans
,
field
,
field
,
ignoreSelects
);
}
}
if
(
trans
.
getParentId
()
!=
null
)
{
buildColumnCAFields
(
tableCA
,
trans
.
getParentId
(),
trans
.
getId
(),
columnCA
,
ignoreSelects
);
}
}
}
private
void
searchSelect
(
TableCA
tableCA
,
ColumnCA
columnCA
,
OperatorTrans
trans
,
String
operation
,
String
alias
,
List
<
Field
>
ignoreSelects
)
{
if
(
MapParseUtils
.
hasField
(
operation
,
columnCA
.
getAlias
()))
{
for
(
Field
field
:
ignoreSelects
)
{
if
(
field
.
getAlias
().
equals
(
columnCA
.
getAlias
()))
{
return
;
}
}
boolean
isHad
=
false
;
Integer
cid
=
null
;
for
(
Map
.
Entry
<
Integer
,
ColumnCA
>
item
:
columnCASMaps
.
entrySet
())
{
ColumnCA
columnCA1
=
item
.
getValue
();
if
(
columnCA1
.
getTableCA
().
getId
().
equals
(
tableCA
.
getId
())
&&
columnCA1
.
getName
().
equals
(
alias
))
{
isHad
=
true
;
cid
=
columnCA1
.
getId
();
break
;
}
}
if
(
columnCA
.
getId
().
equals
(
cid
))
{
return
;
}
if
(!
isHad
)
{
cid
=
index
++;
ColumnCA
columnCA2
=
new
ColumnCA
(
cid
,
alias
,
alias
,
alias
,
alias
,
operation
,
tableCA
);
columnCASMaps
.
put
(
cid
,
columnCA2
);
buildColumnCAFields
(
tableCA
,
trans
.
getParentId
(),
trans
.
getId
(),
columnCA2
,
ignoreSelects
);
}
columnCASRel
.
add
(
new
NodeRel
(
columnCA
.
getId
(),
cid
));
}
}
private
void
searchColumnCAId
(
TableCA
tableCA
)
{
List
<
Integer
>
sufOnly
=
new
ArrayList
<>();
for
(
NodeRel
nodeRel
:
columnCASRel
)
{
if
(!
sufOnly
.
contains
(
nodeRel
.
getSufId
()))
{
sufOnly
.
add
(
nodeRel
.
getSufId
());
}
}
for
(
NodeRel
nodeRel
:
columnCASRel
)
{
if
(
sufOnly
.
contains
(
nodeRel
.
getPreId
()))
{
sufOnly
.
remove
(
nodeRel
.
getPreId
());
}
}
List
<
Integer
>
preOnly
=
new
ArrayList
<>();
for
(
NodeRel
nodeRel
:
columnCASRel
)
{
if
(!
preOnly
.
contains
(
nodeRel
.
getPreId
()))
{
preOnly
.
add
(
nodeRel
.
getPreId
());
}
}
for
(
NodeRel
nodeRel
:
columnCASRel
)
{
if
(
preOnly
.
contains
(
nodeRel
.
getSufId
()))
{
preOnly
.
remove
(
nodeRel
.
getSufId
());
}
}
for
(
int
i
=
0
;
i
<
sufOnly
.
size
();
i
++)
{
ColumnCA
columnCA
=
columnCASMaps
.
get
(
sufOnly
.
get
(
i
));
List
<
String
>
fields
=
tableCA
.
getFields
();
for
(
int
j
=
0
;
j
<
fields
.
size
();
j
++)
{
if
(
columnCA
.
getAlias
().
equals
(
fields
.
get
(
j
)))
{
tableCA
.
getColumnCAIds
().
add
(
sufOnly
.
get
(
i
));
columnCA
.
setTableId
(
tableCA
.
getId
());
break
;
}
}
}
sinkColumns
=
sufOnly
;
sourceColumns
=
preOnly
;
}
private
void
chainRelation
()
{
for
(
Integer
item
:
sourceColumns
)
{
buildSinkSuf
(
item
,
item
);
}
}
private
void
buildSinkSuf
(
Integer
preId
,
Integer
sourcePreId
)
{
for
(
NodeRel
nodeRel
:
columnCASRel
)
{
if
(
nodeRel
.
getPreId
().
equals
(
preId
))
{
Integer
nextSufId
=
nodeRel
.
getSufId
();
if
(
sinkColumns
.
contains
(
nextSufId
))
{
columnCASRelChain
.
add
(
new
NodeRel
(
sourcePreId
,
nextSufId
));
continue
;
}
buildSinkSuf
(
nextSufId
,
sourcePreId
);
}
}
}
public
Map
<
Integer
,
Trans
>
getTransMaps
()
{
return
transMaps
;
}
public
void
setTransMaps
(
Map
<
Integer
,
Trans
>
transMaps
)
{
this
.
transMaps
=
transMaps
;
}
public
List
<
TableCA
>
getTableCAS
()
{
return
tableCAS
;
}
public
void
setTableCAS
(
List
<
TableCA
>
tableCAS
)
{
this
.
tableCAS
=
tableCAS
;
}
public
List
<
ColumnCA
>
getColumnCAS
()
{
return
columnCAS
;
}
public
void
setColumnCAS
(
List
<
ColumnCA
>
columnCAS
)
{
this
.
columnCAS
=
columnCAS
;
}
public
Map
<
Integer
,
ColumnCA
>
getColumnCASMaps
()
{
return
columnCASMaps
;
}
public
void
setColumnCASMaps
(
Map
<
Integer
,
ColumnCA
>
columnCASMaps
)
{
this
.
columnCASMaps
=
columnCASMaps
;
}
public
Set
<
NodeRel
>
getColumnCASRel
()
{
return
columnCASRel
;
}
public
void
setColumnCASRel
(
Set
<
NodeRel
>
columnCASRel
)
{
this
.
columnCASRel
=
columnCASRel
;
}
public
int
getIndex
()
{
return
index
;
}
public
void
setIndex
(
int
index
)
{
this
.
index
=
index
;
}
public
List
<
Integer
>
getSinkColumns
()
{
return
sinkColumns
;
}
public
void
setSinkColumns
(
List
<
Integer
>
sinkColumns
)
{
this
.
sinkColumns
=
sinkColumns
;
}
public
List
<
Integer
>
getSourceColumns
()
{
return
sourceColumns
;
}
public
void
setSourceColumns
(
List
<
Integer
>
sourceColumns
)
{
this
.
sourceColumns
=
sourceColumns
;
}
public
Set
<
NodeRel
>
getColumnCASRelChain
()
{
return
columnCASRelChain
;
}
public
void
setColumnCASRelChain
(
Set
<
NodeRel
>
columnCASRelChain
)
{
this
.
columnCASRelChain
=
columnCASRelChain
;
}
}
dinky-core/src/main/java/org/dinky/explainer/lineage/LineageTable.java
View file @
e6aeea73
...
@@ -19,8 +19,6 @@
...
@@ -19,8 +19,6 @@
package
org
.
dinky
.
explainer
.
lineage
;
package
org
.
dinky
.
explainer
.
lineage
;
import
org.dinky.explainer.ca.TableCA
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -48,18 +46,6 @@ public class LineageTable {
...
@@ -48,18 +46,6 @@ public class LineageTable {
return
new
LineageTable
(
id
,
name
);
return
new
LineageTable
(
id
,
name
);
}
}
public
static
LineageTable
build
(
TableCA
tableCA
)
{
LineageTable
lineageTable
=
new
LineageTable
();
lineageTable
.
setId
(
tableCA
.
getId
().
toString
());
lineageTable
.
setName
(
tableCA
.
getTableName
());
List
<
LineageColumn
>
columnList
=
new
ArrayList
<>();
for
(
String
columnName
:
tableCA
.
getFields
())
{
columnList
.
add
(
LineageColumn
.
build
(
columnName
,
columnName
));
}
lineageTable
.
setColumns
(
columnList
);
return
lineageTable
;
}
public
String
getId
()
{
public
String
getId
()
{
return
id
;
return
id
;
}
}
...
...
dinky-core/src/main/java/org/dinky/explainer/lineage/LineageTableGenerator.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
lineage
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.explainer.ca.TableCA
;
import
org.dinky.explainer.trans.OperatorTrans
;
import
org.dinky.explainer.trans.SinkTrans
;
import
org.dinky.explainer.trans.SourceTrans
;
import
org.dinky.explainer.trans.Trans
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* LineageTableGenerator
*
* @author wenmo
* @since 2022/3/16 19:56
*/
public
class
LineageTableGenerator
{
private
Map
<
Integer
,
Trans
>
transMaps
;
private
List
<
TableCA
>
tables
=
new
ArrayList
<>();
public
LineageTableGenerator
()
{}
public
static
LineageTableGenerator
build
(
List
<
Trans
>
transList
)
{
LineageTableGenerator
generator
=
new
LineageTableGenerator
();
Map
<
Integer
,
Trans
>
map
=
new
HashMap
<>();
for
(
Trans
trans
:
transList
)
{
map
.
put
(
trans
.
getId
(),
trans
);
}
generator
.
setTransMaps
(
map
);
return
generator
;
}
public
void
translate
()
{
for
(
Map
.
Entry
<
Integer
,
Trans
>
entry
:
transMaps
.
entrySet
())
{
if
(
entry
.
getValue
()
instanceof
SourceTrans
)
{
tables
.
add
(
TableCA
.
build
(
entry
.
getValue
()));
}
else
if
(
entry
.
getValue
()
instanceof
SinkTrans
)
{
tables
.
add
(
TableCA
.
build
(
entry
.
getValue
()));
}
else
if
(
entry
.
getValue
()
instanceof
OperatorTrans
)
{
TableCA
tableCA
=
TableCA
.
build
(
entry
.
getValue
());
if
(
Asserts
.
isNotNull
(
tableCA
))
{
tables
.
add
(
tableCA
);
}
}
}
}
public
Map
<
Integer
,
Trans
>
getTransMaps
()
{
return
transMaps
;
}
public
void
setTransMaps
(
Map
<
Integer
,
Trans
>
transMaps
)
{
this
.
transMaps
=
transMaps
;
}
public
List
<
TableCA
>
getTables
()
{
return
tables
;
}
public
void
setTables
(
List
<
TableCA
>
tables
)
{
this
.
tables
=
tables
;
}
}
dinky-core/src/main/java/org/dinky/explainer/trans/AbstractTrans.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
trans
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
com.fasterxml.jackson.databind.JsonNode
;
/**
* AbstractTrans
*
* @author wenmo
* @since 2021/6/22
*/
public
abstract
class
AbstractTrans
{
protected
Integer
id
;
protected
Integer
parentId
;
protected
String
name
;
protected
String
type
;
protected
String
text
;
protected
Integer
stage
;
protected
String
contents
;
protected
String
pact
;
protected
Integer
parallelism
;
protected
List
<
Predecessor
>
predecessors
;
public
void
build
(
JsonNode
node
)
{
id
=
node
.
get
(
"id"
).
asInt
();
text
=
node
.
toPrettyString
();
stage
=
id
;
type
=
matchType
(
node
.
get
(
"type"
).
asText
());
name
=
matchType
(
node
.
get
(
"type"
).
asText
());
pact
=
node
.
get
(
"pact"
).
asText
();
contents
=
matchContents
(
node
.
get
(
"contents"
).
asText
());
translate
();
parallelism
=
node
.
get
(
"parallelism"
).
asInt
();
predecessors
=
new
ArrayList
<>();
if
(
node
.
has
(
"predecessors"
))
{
JsonNode
predecessornodes
=
node
.
get
(
"predecessors"
);
for
(
JsonNode
predecessor
:
predecessornodes
)
{
predecessors
.
add
(
new
Predecessor
(
predecessor
.
get
(
"id"
).
asInt
(),
predecessor
.
get
(
"ship_strategy"
).
asText
(),
predecessor
.
get
(
"side"
).
asText
()));
}
}
}
abstract
void
translate
();
public
static
String
matchType
(
String
str
)
{
Pattern
p
=
Pattern
.
compile
(
"(.*?)\\("
);
Matcher
m
=
p
.
matcher
(
str
);
String
type
=
null
;
if
(
m
.
find
())
{
type
=
m
.
group
(
0
).
replaceAll
(
"\\("
,
""
).
trim
();
}
else
{
type
=
str
;
}
return
type
;
}
public
static
String
matchPact
(
String
str
)
{
Pattern
p
=
Pattern
.
compile
(
": (.*?)$"
);
Matcher
m
=
p
.
matcher
(
str
);
String
pact
=
null
;
if
(
m
.
find
())
{
pact
=
m
.
group
(
0
).
replaceAll
(
": "
,
""
).
trim
();
}
else
{
pact
=
str
;
}
return
pact
;
}
public
static
String
matchContents
(
String
str
)
{
Pattern
p
=
Pattern
.
compile
(
"\\((.*?)$"
);
Matcher
m
=
p
.
matcher
(
str
);
String
contents
=
null
;
if
(
m
.
find
())
{
contents
=
m
.
group
(
0
).
replaceFirst
(
"\\("
,
""
).
trim
();
contents
=
contents
.
substring
(
0
,
contents
.
lastIndexOf
(
")"
));
}
else
{
contents
=
str
;
}
return
contents
;
}
public
static
String
matchStage
(
String
str
)
{
Pattern
p
=
Pattern
.
compile
(
"Stage (.*?) :"
);
Matcher
m
=
p
.
matcher
(
str
);
String
type
=
null
;
if
(
m
.
find
())
{
type
=
m
.
group
(
0
).
replaceFirst
(
"Stage "
,
""
).
replaceFirst
(
" :"
,
""
).
trim
();
}
return
type
;
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Integer
getParentId
()
{
return
parentId
;
}
public
void
setParentId
(
Integer
parentId
)
{
this
.
parentId
=
parentId
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getText
()
{
return
text
;
}
public
void
setText
(
String
text
)
{
this
.
text
=
text
;
}
public
Integer
getStage
()
{
return
stage
;
}
public
void
setStage
(
Integer
stage
)
{
this
.
stage
=
stage
;
}
public
String
getContents
()
{
return
contents
;
}
public
void
setContents
(
String
contents
)
{
this
.
contents
=
contents
;
}
public
String
getPact
()
{
return
pact
;
}
public
void
setPact
(
String
pact
)
{
this
.
pact
=
pact
;
}
public
Integer
getParallelism
()
{
return
parallelism
;
}
public
void
setParallelism
(
Integer
parallelism
)
{
this
.
parallelism
=
parallelism
;
}
public
List
<
Predecessor
>
getPredecessors
()
{
return
predecessors
;
}
public
void
setPredecessors
(
List
<
Predecessor
>
predecessors
)
{
this
.
predecessors
=
predecessors
;
}
}
dinky-core/src/main/java/org/dinky/explainer/trans/Field.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
trans
;
/**
* Field
*
* @author wenmo
* @since 2021/6/22
*/
public
class
Field
{
private
String
fragment
;
private
String
alias
;
public
Field
(
String
fragment
)
{
this
.
fragment
=
fragment
;
this
.
alias
=
fragment
;
}
public
Field
(
String
fragment
,
String
alias
)
{
this
.
fragment
=
fragment
;
this
.
alias
=
alias
;
}
public
String
getFragment
()
{
return
fragment
;
}
public
void
setFragment
(
String
fragment
)
{
this
.
fragment
=
fragment
;
}
public
String
getAlias
()
{
return
alias
;
}
public
void
setAlias
(
String
alias
)
{
this
.
alias
=
alias
;
}
}
dinky-core/src/main/java/org/dinky/explainer/trans/OperatorTrans.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
trans
;
import
org.dinky.utils.MapParseUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* OperatorTrans
*
* @author wenmo
* @since 2021/6/22
*/
public
class
OperatorTrans
extends
AbstractTrans
implements
Trans
{
private
List
<
Field
>
select
;
private
List
<
String
>
table
;
private
List
<
String
>
fields
;
private
List
<
String
>
joinType
;
private
List
<
String
>
lookup
;
private
String
where
;
private
List
<
String
>
leftInputSpec
;
private
List
<
String
>
rightInputSpec
;
public
static
final
String
TRANS_TYPE
=
"Operator"
;
private
static
final
String
FIELD_AS
=
" AS "
;
public
List
<
Field
>
getSelect
()
{
return
select
;
}
public
List
<
String
>
getFields
()
{
return
fields
;
}
public
List
<
String
>
getJoinType
()
{
return
joinType
;
}
public
String
getWhere
()
{
return
where
;
}
public
List
<
String
>
getLeftInputSpec
()
{
return
leftInputSpec
;
}
public
List
<
String
>
getRightInputSpec
()
{
return
rightInputSpec
;
}
public
List
<
String
>
getTable
()
{
return
table
;
}
public
List
<
String
>
getLookup
()
{
return
lookup
;
}
@Override
public
String
getHandle
()
{
return
TRANS_TYPE
;
}
@Override
public
boolean
canHandle
(
String
pact
)
{
return
TRANS_TYPE
.
equals
(
pact
);
}
@Override
public
void
translate
()
{
name
=
pact
;
Map
map
=
MapParseUtils
.
parseForSelect
(
contents
);
translateSelect
((
ArrayList
<
String
>)
map
.
get
(
"select"
));
fields
=
(
ArrayList
<
String
>)
map
.
get
(
"fields"
);
table
=
(
ArrayList
<
String
>)
map
.
get
(
"table"
);
joinType
=
(
ArrayList
<
String
>)
map
.
get
(
"joinType"
);
lookup
=
(
ArrayList
<
String
>)
map
.
get
(
"lookup"
);
where
=
map
.
containsKey
(
"where"
)
?
map
.
get
(
"where"
).
toString
()
:
null
;
leftInputSpec
=
(
ArrayList
<
String
>)
map
.
get
(
"leftInputSpec"
);
rightInputSpec
=
(
ArrayList
<
String
>)
map
.
get
(
"rightInputSpec"
);
}
private
void
translateSelect
(
ArrayList
<
String
>
fieldStrs
)
{
if
(
fieldStrs
!=
null
&&
fieldStrs
.
size
()
>
0
)
{
select
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
fieldStrs
.
size
();
i
++)
{
String
fieldStr
=
fieldStrs
.
get
(
i
).
trim
();
if
(
fieldStr
.
toUpperCase
().
contains
(
FIELD_AS
))
{
String
[]
fieldNames
=
fieldStr
.
split
(
FIELD_AS
);
if
(
fieldNames
.
length
==
2
)
{
select
.
add
(
new
Field
(
fieldNames
[
0
].
trim
(),
fieldNames
[
1
].
trim
()));
}
else
if
(
fieldNames
.
length
==
1
)
{
select
.
add
(
new
Field
(
fieldNames
[
0
].
trim
()));
}
else
{
List
<
String
>
fieldNameList
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
fieldNames
.
length
-
1
;
j
++)
{
fieldNameList
.
add
(
fieldNames
[
j
]);
}
select
.
add
(
new
Field
(
StringUtils
.
join
(
fieldNameList
,
FIELD_AS
).
trim
(),
fieldNames
[
fieldNames
.
length
-
1
].
trim
()));
}
}
else
{
select
.
add
(
new
Field
(
fieldStr
));
}
}
}
}
@Override
public
String
asSummaryString
()
{
return
null
;
}
}
dinky-core/src/main/java/org/dinky/explainer/trans/Predecessor.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
trans
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* Predecessor
*
* @author wenmo
* @since 2021/6/22
*/
@Getter
@Setter
public
class
Predecessor
{
private
Integer
id
;
private
String
shipStrategy
;
private
String
side
;
public
Predecessor
(
Integer
id
,
String
shipStrategy
,
String
side
)
{
this
.
id
=
id
;
this
.
shipStrategy
=
shipStrategy
;
this
.
side
=
side
;
}
@Override
public
String
toString
()
{
return
"Predecessor{"
+
"id="
+
id
+
", shipStrategy='"
+
shipStrategy
+
'\''
+
", side='"
+
side
+
'\''
+
'}'
;
}
}
dinky-core/src/main/java/org/dinky/explainer/trans/SinkTrans.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
trans
;
import
org.dinky.utils.MapParseUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* SinkTrans
*
* @author wenmo
* @since 2021/6/22
*/
public
class
SinkTrans
extends
AbstractTrans
implements
Trans
{
private
String
catalog
;
private
String
database
;
private
String
table
;
private
List
<
String
>
fields
;
public
static
final
String
TRANS_TYPE
=
"Data Sink"
;
public
SinkTrans
()
{}
public
String
getCatalog
()
{
return
catalog
;
}
public
void
setCatalog
(
String
catalog
)
{
this
.
catalog
=
catalog
;
}
public
String
getDatabase
()
{
return
database
;
}
public
void
setDatabase
(
String
database
)
{
this
.
database
=
database
;
}
public
String
getTable
()
{
return
table
;
}
public
void
setTable
(
String
table
)
{
this
.
table
=
table
;
}
public
List
<
String
>
getFields
()
{
return
fields
;
}
public
void
setFields
(
List
<
String
>
fields
)
{
this
.
fields
=
fields
;
}
@Override
public
String
getHandle
()
{
return
TRANS_TYPE
;
}
@Override
public
boolean
canHandle
(
String
pact
)
{
return
TRANS_TYPE
.
equals
(
pact
);
}
@Override
public
void
translate
()
{
Map
map
=
MapParseUtils
.
parse
(
contents
);
ArrayList
<
String
>
tables
=
(
ArrayList
<
String
>)
map
.
get
(
"table"
);
if
(
tables
!=
null
&&
tables
.
size
()
>
0
)
{
name
=
tables
.
get
(
0
);
String
[]
names
=
tables
.
get
(
0
).
split
(
"\\."
);
if
(
names
.
length
>=
3
)
{
catalog
=
names
[
0
];
database
=
names
[
1
];
table
=
names
[
2
];
}
else
{
table
=
name
;
}
}
fields
=
(
ArrayList
<
String
>)
map
.
get
(
"fields"
);
}
@Override
public
String
asSummaryString
()
{
return
""
;
}
}
dinky-core/src/main/java/org/dinky/explainer/trans/SourceTrans.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
trans
;
import
org.dinky.utils.MapParseUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.flink.table.operations.Operation
;
import
org.apache.flink.table.operations.OperationUtils
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* SourceTrans
*
* @author wenmo
* @since 2021/6/22
*/
public
class
SourceTrans
extends
AbstractTrans
implements
Trans
{
private
String
catalog
;
private
String
database
;
private
String
table
;
private
List
<
String
>
project
;
private
List
<
String
>
fields
;
public
static
final
String
TRANS_TYPE
=
"Data Source"
;
public
SourceTrans
()
{}
public
String
getCatalog
()
{
return
catalog
;
}
public
String
getDatabase
()
{
return
database
;
}
public
String
getTable
()
{
return
table
;
}
public
List
<
String
>
getProject
()
{
return
project
;
}
public
List
<
String
>
getFields
()
{
return
fields
;
}
@Override
public
String
getHandle
()
{
return
TRANS_TYPE
;
}
@Override
public
boolean
canHandle
(
String
pact
)
{
return
TRANS_TYPE
.
equals
(
pact
);
}
@Override
public
String
asSummaryString
()
{
Map
<
String
,
Object
>
params
=
new
LinkedHashMap
<>();
/*
* params.put("originalQuery", catalogView.getOriginalQuery()); params.put("expandedQuery",
* catalogView.getExpandedQuery()); params.put("identifier", viewIdentifier); params.put("ignoreIfExists",
* ignoreIfExists); params.put("isTemporary", isTemporary);
*/
return
OperationUtils
.
formatWithChildren
(
"CREATE VIEW"
,
params
,
Collections
.
emptyList
(),
Operation:
:
asSummaryString
);
}
@Override
public
void
translate
()
{
Map
map
=
MapParseUtils
.
parse
(
contents
);
ArrayList
<
ArrayList
<
Object
>>
tables
=
(
ArrayList
<
ArrayList
<
Object
>>)
map
.
get
(
"table"
);
ArrayList
<
Object
>
names
=
tables
.
get
(
0
);
if
(
names
.
size
()
==
4
)
{
project
=
(
ArrayList
<
String
>)
((
Map
)
names
.
get
(
3
)).
get
(
"project"
);
names
.
remove
(
3
);
}
name
=
StringUtils
.
join
(
names
,
"."
);
if
(
names
.
size
()
>=
3
)
{
catalog
=
names
.
get
(
0
).
toString
();
database
=
names
.
get
(
1
).
toString
();
table
=
names
.
get
(
2
).
toString
();
}
else
{
table
=
name
;
}
fields
=
(
ArrayList
<
String
>)
map
.
get
(
"fields"
);
}
}
dinky-core/src/main/java/org/dinky/explainer/trans/Trans.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
trans
;
import
java.util.List
;
import
com.fasterxml.jackson.databind.JsonNode
;
/**
* Trans
*
* @author wenmo
* @since 2021/6/22
*/
public
interface
Trans
{
String
getHandle
();
boolean
canHandle
(
String
pact
);
void
build
(
JsonNode
node
);
void
translate
();
String
asSummaryString
();
Integer
getId
();
List
<
Predecessor
>
getPredecessors
();
void
setParentId
(
Integer
parentId
);
Integer
getParentId
();
String
getPact
();
}
dinky-core/src/main/java/org/dinky/explainer/trans/TransGenerator.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
explainer
.
trans
;
import
org.dinky.assertion.Asserts
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
/**
* TransGenerator
*
* @author wenmo
* @since 2021/6/22
*/
public
class
TransGenerator
{
private
ObjectNode
plan
;
public
TransGenerator
(
ObjectNode
plan
)
{
this
.
plan
=
plan
;
}
public
static
Trans
getTrans
(
String
pact
)
{
switch
(
pact
)
{
case
OperatorTrans
.
TRANS_TYPE
:
return
new
OperatorTrans
();
case
SourceTrans
.
TRANS_TYPE
:
return
new
SourceTrans
();
case
SinkTrans
.
TRANS_TYPE
:
return
new
SinkTrans
();
default
:
return
null
;
}
}
public
List
<
Trans
>
translateTrans
()
{
JsonNode
nodes
=
plan
.
get
(
"nodes"
);
List
<
Trans
>
nodeList
=
new
ArrayList
<>();
Map
<
Integer
,
Trans
>
nodemap
=
new
HashMap
<>();
for
(
JsonNode
node
:
nodes
)
{
String
pact
=
node
.
get
(
"pact"
).
asText
();
Trans
trans
=
getTrans
(
pact
);
Asserts
.
checkNotNull
(
trans
,
"该转换无法被解析,原文如下:"
+
pact
);
trans
.
build
(
node
);
nodemap
.
put
(
trans
.
getId
(),
trans
);
}
setParentId
(
nodemap
);
for
(
Map
.
Entry
<
Integer
,
Trans
>
entry
:
nodemap
.
entrySet
())
{
nodeList
.
add
(
entry
.
getValue
());
}
return
nodeList
;
}
private
void
setParentId
(
Map
<
Integer
,
Trans
>
nodemap
)
{
for
(
Map
.
Entry
<
Integer
,
Trans
>
entry
:
nodemap
.
entrySet
())
{
Trans
trans
=
entry
.
getValue
();
List
<
Predecessor
>
predecessors
=
trans
.
getPredecessors
();
if
(
Asserts
.
isNullCollection
(
predecessors
))
{
continue
;
}
for
(
int
i
=
0
;
i
<
predecessors
.
size
();
i
++)
{
nodemap
.
get
(
predecessors
.
get
(
i
).
getId
()).
setParentId
(
trans
.
getId
());
}
}
}
}
dinky-core/src/main/java/org/dinky/plus/FlinkSqlPlus.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
plus
;
import
org.dinky.executor.Executor
;
import
org.dinky.explainer.Explainer
;
import
org.dinky.explainer.ca.ColumnCAResult
;
import
org.dinky.explainer.ca.TableCAResult
;
import
org.dinky.model.LineageRel
;
import
org.dinky.result.SqlExplainResult
;
import
org.apache.flink.runtime.rest.messages.JobPlanInfo
;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
/**
* FlinkSqlPlus
*
* @author wenmo
* @since 2021/6/22
*/
public
class
FlinkSqlPlus
{
private
Executor
executor
;
private
Explainer
explainer
;
private
boolean
statementSet
;
public
FlinkSqlPlus
(
Executor
executor
)
{
this
.
executor
=
executor
;
this
.
explainer
=
new
Explainer
(
executor
);
}
public
FlinkSqlPlus
(
Executor
executor
,
boolean
statementSet
)
{
this
.
executor
=
executor
;
this
.
explainer
=
new
Explainer
(
executor
,
statementSet
);
}
public
static
FlinkSqlPlus
build
()
{
return
build
(
true
);
}
public
static
FlinkSqlPlus
build
(
boolean
statementSet
)
{
return
new
FlinkSqlPlus
(
Executor
.
build
(),
statementSet
);
}
public
List
<
SqlResult
>
executeSql
(
String
sql
)
{
if
(
sql
==
null
||
""
.
equals
(
sql
))
{
return
new
ArrayList
<>();
}
String
[]
sqls
=
sql
.
split
(
";"
);
List
<
SqlResult
>
sqlResults
=
new
ArrayList
<>();
try
{
for
(
int
i
=
0
;
i
<
sqls
.
length
;
i
++)
{
sqlResults
.
add
(
new
SqlResult
(
executor
.
executeSql
(
sqls
[
i
])));
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
sqlResults
.
add
(
new
SqlResult
(
false
,
e
.
getMessage
()));
return
sqlResults
;
}
return
sqlResults
;
}
public
SqlResult
execute
(
String
sql
)
{
if
(
sql
==
null
||
""
.
equals
(
sql
))
{
return
SqlResult
.
NULL
;
}
try
{
return
new
SqlResult
(
executor
.
executeSql
(
sql
));
}
catch
(
Exception
e
)
{
return
new
SqlResult
(
false
,
e
.
getMessage
());
}
}
public
List
<
SqlExplainResult
>
explainSqlRecord
(
String
statement
)
{
return
explainer
.
explainSqlResult
(
statement
);
}
public
List
<
TableCAResult
>
explainSqlTableColumnCA
(
String
statement
)
{
return
explainer
.
explainSqlTableColumnCA
(
statement
);
}
public
List
<
TableCAResult
>
generateTableCA
(
String
statement
)
{
return
explainer
.
generateTableCA
(
statement
);
}
@Deprecated
public
List
<
ColumnCAResult
>
explainSqlColumnCA
(
String
statement
)
{
return
explainer
.
explainSqlColumnCA
(
statement
);
}
public
ObjectNode
getStreamGraph
(
String
statement
)
{
return
executor
.
getStreamGraph
(
statement
);
}
public
JobPlanInfo
getJobPlanInfo
(
String
statement
)
{
return
explainer
.
getJobPlanInfo
(
statement
);
}
public
List
<
LineageRel
>
getLineage
(
String
statement
)
{
return
explainer
.
getLineage
(
statement
);
}
}
dinky-core/src/test/java/org/dinky/core/FlinkSqlPlusTest.java
deleted
100644 → 0
View file @
63ea7d98
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
core
;
import
org.dinky.plus.FlinkSqlPlus
;
import
org.apache.flink.runtime.rest.messages.JobPlanInfo
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* FlinkSqlPlusTest
*
* @author wenmo
* @since 2021/6/23 10:37
*/
@Ignore
public
class
FlinkSqlPlusTest
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
FlinkSqlPlusTest
.
class
);
@Ignore
@Test
public
void
getJobPlanInfo
()
{
String
sql
=
"jdbcconfig:='connector' = 'jdbc',\n"
+
" 'url' = 'jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false"
+
"&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true',\n"
+
" 'username'='dinky',\n"
+
" 'password'='dinky',;\n"
+
"create temporary function TOP2 as 'org.dinky.ud.udtaf.Top2';\n"
+
"CREATE TABLE student (\n"
+
" sid INT,\n"
+
" name STRING,\n"
+
" PRIMARY KEY (sid) NOT ENFORCED\n"
+
") WITH (\n"
+
" ${jdbcconfig}\n"
+
" 'table-name' = 'student'\n"
+
");\n"
+
"CREATE TABLE score (\n"
+
" cid INT,\n"
+
" sid INT,\n"
+
" cls STRING,\n"
+
" score INT,\n"
+
" PRIMARY KEY (cid) NOT ENFORCED\n"
+
") WITH (\n"
+
" ${jdbcconfig}\n"
+
" 'table-name' = 'score'\n"
+
");\n"
+
"CREATE TABLE scoretop2 (\n"
+
" cls STRING,\n"
+
" score INT,\n"
+
" `rank` INT,\n"
+
" PRIMARY KEY (cls,`rank`) NOT ENFORCED\n"
+
") WITH (\n"
+
" ${jdbcconfig}\n"
+
" 'table-name' = 'scoretop2'\n"
+
");\n"
+
"CREATE AGGTABLE aggscore AS \n"
+
"SELECT cls,score,rank\n"
+
"FROM score\n"
+
"GROUP BY cls\n"
+
"AGG BY TOP2(score) as (score,rank);\n"
+
"insert into scoretop2\n"
+
"select \n"
+
"b.cls,b.score,b.`rank`\n"
+
"from aggscore b"
;
FlinkSqlPlus
plus
=
FlinkSqlPlus
.
build
();
JobPlanInfo
jobPlanInfo
=
plus
.
getJobPlanInfo
(
sql
);
LOGGER
.
info
(
jobPlanInfo
.
getJsonPlan
());
}
}
dlink-web/src/components/Studio/StudioTree/components/SimpleTaskForm.tsx
View file @
e6aeea73
...
@@ -193,7 +193,7 @@ const SimpleTaskForm: React.FC<UpdateFormProps> = (props) => {
...
@@ -193,7 +193,7 @@ const SimpleTaskForm: React.FC<UpdateFormProps> = (props) => {
bodyStyle=
{
{
padding
:
'32px 40px 48px'
}
}
bodyStyle=
{
{
padding
:
'32px 40px 48px'
}
}
destroyOnClose
destroyOnClose
title=
{
isCreate
?
'创建新作业'
:
(
'重命名作业-'
+
formVals
.
name
)
}
title=
{
isCreate
?
'创建新作业'
:
(
'重命名作业-'
+
formVals
.
name
)
}
open
=
{
updateModalVisible
}
visible
=
{
updateModalVisible
}
footer=
{
renderFooter
()
}
footer=
{
renderFooter
()
}
onCancel=
{
()
=>
handleUpdateModalVisible
()
}
onCancel=
{
()
=>
handleUpdateModalVisible
()
}
>
>
...
...
dlink-web/src/components/Studio/StudioTree/components/UpdateCatalogueForm.tsx
View file @
e6aeea73
...
@@ -94,7 +94,7 @@ const UpdateCatalogueForm: React.FC<UpdateFormProps> = (props) => {
...
@@ -94,7 +94,7 @@ const UpdateCatalogueForm: React.FC<UpdateFormProps> = (props) => {
bodyStyle=
{
{
padding
:
'32px 40px 48px'
}
}
bodyStyle=
{
{
padding
:
'32px 40px 48px'
}
}
destroyOnClose
destroyOnClose
title=
{
isCreate
?
'创建新目录'
:
(
'重命名目录-'
+
formVals
.
name
)
}
title=
{
isCreate
?
'创建新目录'
:
(
'重命名目录-'
+
formVals
.
name
)
}
open
=
{
updateModalVisible
}
visible
=
{
updateModalVisible
}
footer=
{
renderFooter
()
}
footer=
{
renderFooter
()
}
onCancel=
{
()
=>
handleUpdateModalVisible
()
}
onCancel=
{
()
=>
handleUpdateModalVisible
()
}
>
>
...
...
dlink-web/src/components/Studio/StudioTree/components/UploadModal.tsx
View file @
e6aeea73
...
@@ -59,7 +59,7 @@ const UploadModal: React.FC<UploadModalProps> = (props: any) => {
...
@@ -59,7 +59,7 @@ const UploadModal: React.FC<UploadModalProps> = (props: any) => {
return
(
return
(
<
div
>
<
div
>
<
Modal
title=
"上传文件"
<
Modal
title=
"上传文件"
open
=
{
visible
}
visible
=
{
visible
}
onOk=
{
handleOk
}
onOk=
{
handleOk
}
onCancel=
{
onCancel
}
onCancel=
{
onCancel
}
maskClosable=
{
false
}
maskClosable=
{
false
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment