Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dlink
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
zhaowei
dlink
Commits
730e5822
Commit
730e5822
authored
Jun 16, 2021
by
wenmo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0.2.2-rc2
parent
bea8e111
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
1306 additions
and
54 deletions
+1306
-54
README.md
README.md
+1
-1
StudioServiceImpl.java
...c/main/java/com/dlink/service/impl/StudioServiceImpl.java
+19
-8
TaskServiceImpl.java
...src/main/java/com/dlink/service/impl/TaskServiceImpl.java
+4
-4
pom.xml
dlink-client/dlink-client-1.13/pom.xml
+106
-0
CustomTableEnvironmentImpl.java
...com/dlink/executor/custom/CustomTableEnvironmentImpl.java
+293
-0
CustomTableResultImpl.java
...java/com/dlink/executor/custom/CustomTableResultImpl.java
+282
-0
SqlManager.java
...3/src/main/java/com/dlink/executor/custom/SqlManager.java
+194
-0
TableSchemaField.java
...main/java/com/dlink/executor/custom/TableSchemaField.java
+33
-0
SqlExplainResult.java
...1.13/src/main/java/com/dlink/result/SqlExplainResult.java
+108
-0
JSONGenerator.java
...a/org/apache/flink/streaming/api/graph/JSONGenerator.java
+186
-0
pom.xml
dlink-client/pom.xml
+1
-0
pom.xml
dlink-core/pom.xml
+3
-3
JobManager.java
dlink-core/src/main/java/com/dlink/job/JobManager.java
+47
-22
JobManagerTest.java
dlink-core/src/test/java/com/dlink/core/JobManagerTest.java
+7
-6
index.tsx
dlink-web/src/components/Studio/StudioMenu/index.tsx
+1
-1
index.tsx
dlink-web/src/components/Studio/StudioSetting/index.tsx
+6
-4
index.tsx
dlink-web/src/components/Studio/StudioTree/index.tsx
+3
-2
model.ts
dlink-web/src/pages/FlinkSqlStudio/model.ts
+3
-3
Welcome.tsx
dlink-web/src/pages/Welcome.tsx
+9
-0
No files found.
README.md
View file @
730e5822
...
...
@@ -93,7 +93,7 @@ DataLink 开源项目及社区正在建设,希望本项目可以帮助你更
### 最新版本
dlink-0.2.2
-rc1
dlink-0.2.2
### 从安装包开始
...
...
dlink-admin/src/main/java/com/dlink/service/impl/StudioServiceImpl.java
View file @
730e5822
...
...
@@ -47,10 +47,18 @@ public class StudioServiceImpl implements StudioService {
clusterService
.
updateById
(
cluster
);
}
}
JobManager
jobManager
=
new
JobManager
(
host
,
studioExecuteDTO
.
getSession
(),
studioExecuteDTO
.
getMaxRowNum
());
return
jobManager
.
execute
(
studioExecuteDTO
.
getStatement
(),
new
ExecutorSetting
(
ExecuteType
,
studioExecuteDTO
.
getCheckPoint
(),
studioExecuteDTO
.
getParallelism
(),
studioExecuteDTO
.
isFragment
(),
studioExecuteDTO
.
getSavePointPath
(),
studioExecuteDTO
.
getJobName
()));
JobManager
jobManager
=
new
JobManager
(
host
,
studioExecuteDTO
.
getSession
(),
studioExecuteDTO
.
getMaxRowNum
(),
new
ExecutorSetting
(
ExecuteType
,
studioExecuteDTO
.
getCheckPoint
(),
studioExecuteDTO
.
getParallelism
(),
studioExecuteDTO
.
isFragment
(),
studioExecuteDTO
.
getSavePointPath
(),
studioExecuteDTO
.
getJobName
()));
return
jobManager
.
execute
(
studioExecuteDTO
.
getStatement
());
}
@Override
...
...
@@ -70,10 +78,13 @@ public class StudioServiceImpl implements StudioService {
clusterService
.
updateById
(
cluster
);
}
}
JobManager
jobManager
=
new
JobManager
(
host
,
studioDDLDTO
.
getSession
(),
1000
);
return
jobManager
.
execute
(
studioDDLDTO
.
getStatement
(),
new
ExecutorSetting
(
ExecuteType
));
}
JobManager
jobManager
=
new
JobManager
(
host
,
studioDDLDTO
.
getSession
(),
1000
,
new
ExecutorSetting
(
ExecuteType
));
return
jobManager
.
execute
(
studioDDLDTO
.
getStatement
());
}
@Override
public
boolean
clearSession
(
String
session
)
{
...
...
dlink-admin/src/main/java/com/dlink/service/impl/TaskServiceImpl.java
View file @
730e5822
...
...
@@ -47,11 +47,11 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
cluster
.
setJobManagerHost
(
host
);
clusterService
.
updateById
(
cluster
);
}
JobManager
jobManager
=
new
JobManager
(
host
);
return
jobManager
.
submit
(
statement
.
getStatement
()
,
task
.
getRemoteExecutorSetting
()
);
JobManager
jobManager
=
new
JobManager
(
host
,
task
.
getRemoteExecutorSetting
()
);
return
jobManager
.
submit
(
statement
.
getStatement
());
}
else
if
(
task
.
getClusterId
()==
0
){
JobManager
jobManager
=
new
JobManager
();
return
jobManager
.
submit
(
statement
.
getStatement
()
,
task
.
getLocalExecutorSetting
()
);
JobManager
jobManager
=
new
JobManager
(
task
.
getLocalExecutorSetting
()
);
return
jobManager
.
submit
(
statement
.
getStatement
());
}
else
{
throw
new
BusException
(
"该任务的集群不存在"
);
}
...
...
dlink-client/dlink-client-1.13/pom.xml
0 → 100644
View file @
730e5822
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
dlink-client
</artifactId>
<groupId>
com.dlink
</groupId>
<version>
0.3.0-SANPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<packaging>
jar
</packaging>
<artifactId>
dlink-client-1.13
</artifactId>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<flink.version>
1.13.1
</flink.version>
<scala.binary.version>
2.11
</scala.binary.version>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<junit.version>
4.12
</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.apache.flink
</groupId>
<artifactId>
flink-table-planner-blink_${scala.binary.version}
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</exclusion>
</exclusions>
<version>
${flink.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.flink
</groupId>
<artifactId>
flink-clients_${scala.binary.version}
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</exclusion>
</exclusions>
<version>
${flink.version}
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.8.0
</version>
<configuration>
<source>
1.8
</source>
<target>
1.8
</target>
</configuration>
</plugin>
<!--打jar包-->
<plugin>
<artifactId>
maven-assembly-plugin
</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-shade-plugin
</artifactId>
<version>
3.2.1
</version>
<configuration>
<filters>
<filter>
<artifact>
*:*
</artifact>
<excludes>
<exclude>
META-INF/*.SF
</exclude>
<exclude>
META-INF/*.DSA
</exclude>
<exclude>
META-INF/*.RSA
</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
shade
</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation=
"org.apache.maven.plugins.shade.resource.AppendingTransformer"
>
<resource>
reference.conf
</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
dlink-client/dlink-client-1.13/src/main/java/com/dlink/executor/custom/CustomTableEnvironmentImpl.java
0 → 100644
View file @
730e5822
package
com
.
dlink
.
executor
.
custom
;
import
com.dlink.result.SqlExplainResult
;
import
org.apache.flink.api.common.typeinfo.TypeInformation
;
import
org.apache.flink.api.dag.Transformation
;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
;
import
org.apache.flink.streaming.api.graph.JSONGenerator
;
import
org.apache.flink.streaming.api.graph.StreamGraph
;
import
org.apache.flink.table.api.*
;
import
org.apache.flink.table.api.internal.TableEnvironmentImpl
;
import
org.apache.flink.table.catalog.CatalogManager
;
import
org.apache.flink.table.catalog.FunctionCatalog
;
import
org.apache.flink.table.catalog.GenericInMemoryCatalog
;
import
org.apache.flink.table.delegation.Executor
;
import
org.apache.flink.table.delegation.ExecutorFactory
;
import
org.apache.flink.table.delegation.Planner
;
import
org.apache.flink.table.delegation.PlannerFactory
;
import
org.apache.flink.table.factories.ComponentFactoryService
;
import
org.apache.flink.table.functions.AggregateFunction
;
import
org.apache.flink.table.functions.TableAggregateFunction
;
import
org.apache.flink.table.functions.TableFunction
;
import
org.apache.flink.table.functions.UserDefinedFunctionHelper
;
import
org.apache.flink.table.module.ModuleManager
;
import
org.apache.flink.table.operations.ExplainOperation
;
import
org.apache.flink.table.operations.ModifyOperation
;
import
org.apache.flink.table.operations.Operation
;
import
org.apache.flink.table.operations.QueryOperation
;
import
org.apache.flink.table.planner.delegation.ExecutorBase
;
import
org.apache.flink.table.planner.utils.ExecutorUtils
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* 定制TableEnvironmentImpl
*
* @author wenmo
* @since 2021/6/7 22:06
**/
public
class
CustomTableEnvironmentImpl
extends
TableEnvironmentImpl
{
private
SqlManager
sqlManager
;
private
boolean
useSqlFragment
=
true
;
protected
CustomTableEnvironmentImpl
(
CatalogManager
catalogManager
,
SqlManager
sqlManager
,
ModuleManager
moduleManager
,
TableConfig
tableConfig
,
Executor
executor
,
FunctionCatalog
functionCatalog
,
Planner
planner
,
boolean
isStreamingMode
,
ClassLoader
userClassLoader
)
{
super
(
catalogManager
,
moduleManager
,
tableConfig
,
executor
,
functionCatalog
,
planner
,
isStreamingMode
,
userClassLoader
);
this
.
sqlManager
=
sqlManager
;
}
public
static
CustomTableEnvironmentImpl
create
(
StreamExecutionEnvironment
executionEnvironment
)
{
return
create
(
executionEnvironment
,
EnvironmentSettings
.
newInstance
().
build
());
}
static
CustomTableEnvironmentImpl
create
(
StreamExecutionEnvironment
executionEnvironment
,
EnvironmentSettings
settings
)
{
return
create
(
executionEnvironment
,
settings
,
new
TableConfig
());
}
public
static
CustomTableEnvironmentImpl
create
(
StreamExecutionEnvironment
executionEnvironment
,
EnvironmentSettings
settings
,
TableConfig
tableConfig
)
{
if
(!
settings
.
isStreamingMode
())
{
throw
new
TableException
(
"StreamTableEnvironment can not run in batch mode for now, please use TableEnvironment."
);
}
else
{
ClassLoader
classLoader
=
Thread
.
currentThread
().
getContextClassLoader
();
ModuleManager
moduleManager
=
new
ModuleManager
();
SqlManager
sqlManager
=
new
SqlManager
();
CatalogManager
catalogManager
=
CatalogManager
.
newBuilder
().
classLoader
(
classLoader
).
config
(
tableConfig
.
getConfiguration
()).
defaultCatalog
(
settings
.
getBuiltInCatalogName
(),
new
GenericInMemoryCatalog
(
settings
.
getBuiltInCatalogName
(),
settings
.
getBuiltInDatabaseName
())).
executionConfig
(
executionEnvironment
.
getConfig
()).
build
();
FunctionCatalog
functionCatalog
=
new
FunctionCatalog
(
tableConfig
,
catalogManager
,
moduleManager
);
Map
<
String
,
String
>
executorProperties
=
settings
.
toExecutorProperties
();
Executor
executor
=
lookupExecutor
(
executorProperties
,
executionEnvironment
);
Map
<
String
,
String
>
plannerProperties
=
settings
.
toPlannerProperties
();
Planner
planner
=
((
PlannerFactory
)
ComponentFactoryService
.
find
(
PlannerFactory
.
class
,
plannerProperties
)).
create
(
plannerProperties
,
executor
,
tableConfig
,
functionCatalog
,
catalogManager
);
return
new
CustomTableEnvironmentImpl
(
catalogManager
,
sqlManager
,
moduleManager
,
tableConfig
,
executor
,
functionCatalog
,
planner
,
settings
.
isStreamingMode
(),
classLoader
);
}
}
private
static
Executor
lookupExecutor
(
Map
<
String
,
String
>
executorProperties
,
StreamExecutionEnvironment
executionEnvironment
)
{
try
{
ExecutorFactory
executorFactory
=
(
ExecutorFactory
)
ComponentFactoryService
.
find
(
ExecutorFactory
.
class
,
executorProperties
);
Method
createMethod
=
executorFactory
.
getClass
().
getMethod
(
"create"
,
Map
.
class
,
StreamExecutionEnvironment
.
class
);
return
(
Executor
)
createMethod
.
invoke
(
executorFactory
,
executorProperties
,
executionEnvironment
);
}
catch
(
Exception
var4
)
{
throw
new
TableException
(
"Could not instantiate the executor. Make sure a planner module is on the classpath"
,
var4
);
}
}
public
void
useSqlFragment
()
{
this
.
useSqlFragment
=
true
;
}
public
void
unUseSqlFragment
()
{
this
.
useSqlFragment
=
false
;
}
@Override
public
String
explainSql
(
String
statement
,
ExplainDetail
...
extraDetails
)
{
if
(
useSqlFragment
)
{
statement
=
sqlManager
.
parseVariable
(
statement
);
if
(
statement
.
length
()
==
0
)
{
return
"This is a sql fragment."
;
}
}
if
(
checkShowFragments
(
statement
))
{
return
"'SHOW FRAGMENTS' can't be explained."
;
}
else
{
return
super
.
explainSql
(
statement
,
extraDetails
);
}
}
public
String
getStreamGraphString
(
String
statement
)
{
if
(
useSqlFragment
)
{
statement
=
sqlManager
.
parseVariable
(
statement
);
if
(
statement
.
length
()
==
0
)
{
return
"This is a sql fragment."
;
}
}
if
(
checkShowFragments
(
statement
))
{
return
"'SHOW FRAGMENTS' can't be explained."
;
}
List
<
Operation
>
operations
=
super
.
getParser
().
parse
(
statement
);
if
(
operations
.
size
()
!=
1
)
{
throw
new
TableException
(
"Unsupported SQL query! explainSql() only accepts a single SQL query."
);
}
else
{
List
<
ModifyOperation
>
modifyOperations
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
operations
.
size
();
i
++)
{
if
(
operations
.
get
(
i
)
instanceof
ModifyOperation
){
modifyOperations
.
add
((
ModifyOperation
)
operations
.
get
(
i
));
}
}
List
<
Transformation
<?>>
trans
=
super
.
planner
.
translate
(
modifyOperations
);
if
(
execEnv
instanceof
ExecutorBase
){
return
ExecutorUtils
.
generateStreamGraph
(((
ExecutorBase
)
execEnv
).
getExecutionEnvironment
(),
trans
).
getStreamingPlanAsJSON
();
}
else
{
return
"Unsupported SQL query! explainSql() need a single SQL to query."
;
}
}
}
public
ObjectNode
getStreamGraph
(
String
statement
)
{
if
(
useSqlFragment
)
{
statement
=
sqlManager
.
parseVariable
(
statement
);
if
(
statement
.
length
()
==
0
)
{
throw
new
TableException
(
"This is a sql fragment."
);
}
}
if
(
checkShowFragments
(
statement
))
{
throw
new
TableException
(
"'SHOW FRAGMENTS' can't be explained."
);
}
List
<
Operation
>
operations
=
super
.
getParser
().
parse
(
statement
);
if
(
operations
.
size
()
!=
1
)
{
throw
new
TableException
(
"Unsupported SQL query! explainSql() only accepts a single SQL query."
);
}
else
{
List
<
ModifyOperation
>
modifyOperations
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
operations
.
size
();
i
++)
{
if
(
operations
.
get
(
i
)
instanceof
ModifyOperation
){
modifyOperations
.
add
((
ModifyOperation
)
operations
.
get
(
i
));
}
}
List
<
Transformation
<?>>
trans
=
super
.
planner
.
translate
(
modifyOperations
);
if
(
execEnv
instanceof
ExecutorBase
){
StreamGraph
streamGraph
=
ExecutorUtils
.
generateStreamGraph
(((
ExecutorBase
)
execEnv
).
getExecutionEnvironment
(),
trans
);
JSONGenerator
jsonGenerator
=
new
JSONGenerator
(
streamGraph
);
ObjectNode
jsonNode
=
jsonGenerator
.
getJSONNode
();
return
jsonNode
;
}
else
{
throw
new
TableException
(
"Unsupported SQL query! explainSql() need a single SQL to query."
);
}
}
}
public
SqlExplainResult
explainSqlRecord
(
String
statement
,
ExplainDetail
...
extraDetails
)
{
SqlExplainResult
record
=
new
SqlExplainResult
();
if
(
useSqlFragment
)
{
String
orignSql
=
statement
;
statement
=
sqlManager
.
parseVariable
(
statement
);
if
(
statement
.
length
()
==
0
)
{
record
.
setParseTrue
(
true
);
record
.
setType
(
"Sql Fragment"
);
record
.
setExplain
(
orignSql
);
record
.
setExplainTrue
(
true
);
return
record
;
}
}
List
<
Operation
>
operations
=
getParser
().
parse
(
statement
);
record
.
setParseTrue
(
true
);
if
(
operations
.
size
()
!=
1
)
{
throw
new
TableException
(
"Unsupported SQL query! explainSql() only accepts a single SQL query."
);
}
List
<
Operation
>
operationlist
=
new
ArrayList
<>(
operations
);
for
(
int
i
=
0
;
i
<
operationlist
.
size
();
i
++)
{
Operation
operation
=
operationlist
.
get
(
i
);
if
(
operation
instanceof
ModifyOperation
)
{
record
.
setType
(
"Modify DML"
);
}
else
if
(
operation
instanceof
ExplainOperation
)
{
record
.
setType
(
"Explain DML"
);
}
else
if
(
operation
instanceof
QueryOperation
)
{
record
.
setType
(
"Query DML"
);
}
else
{
operationlist
.
remove
(
i
);
record
.
setType
(
"DDL"
);
i
=
i
-
1
;
}
}
if
(
operationlist
.
size
()==
0
){
//record.setExplain("DDL语句不进行解释。");
return
record
;
}
record
.
setExplain
(
planner
.
explain
(
operationlist
,
extraDetails
));
record
.
setExplainTrue
(
true
);
return
record
;
}
@Override
public
String
[]
getCompletionHints
(
String
statement
,
int
position
)
{
if
(
useSqlFragment
)
{
statement
=
sqlManager
.
parseVariable
(
statement
);
if
(
statement
.
length
()
==
0
)
{
return
new
String
[
0
];
}
}
return
super
.
getCompletionHints
(
statement
,
position
);
}
@Override
public
Table
sqlQuery
(
String
query
)
{
if
(
useSqlFragment
)
{
query
=
sqlManager
.
parseVariable
(
query
);
if
(
query
.
length
()
==
0
)
{
throw
new
TableException
(
"Unsupported SQL query! The SQL query parsed is null.If it's a sql fragment, and please use executeSql()."
);
}
if
(
checkShowFragments
(
query
))
{
return
sqlManager
.
getSqlFragmentsTable
(
this
);
}
else
{
return
super
.
sqlQuery
(
query
);
}
}
else
{
return
super
.
sqlQuery
(
query
);
}
}
@Override
public
TableResult
executeSql
(
String
statement
)
{
if
(
useSqlFragment
)
{
statement
=
sqlManager
.
parseVariable
(
statement
);
if
(
statement
.
length
()
==
0
)
{
return
CustomTableResultImpl
.
TABLE_RESULT_OK
;
}
if
(
checkShowFragments
(
statement
))
{
return
sqlManager
.
getSqlFragments
();
}
else
{
return
super
.
executeSql
(
statement
);
}
}
else
{
return
super
.
executeSql
(
statement
);
}
}
@Override
public
void
sqlUpdate
(
String
stmt
)
{
if
(
useSqlFragment
)
{
stmt
=
sqlManager
.
parseVariable
(
stmt
);
if
(
stmt
.
length
()
==
0
)
{
throw
new
TableException
(
"Unsupported SQL update! The SQL update parsed is null.If it's a sql fragment, and please use executeSql()."
);
}
}
super
.
sqlUpdate
(
stmt
);
}
public
boolean
checkShowFragments
(
String
sql
){
return
sqlManager
.
checkShowFragments
(
sql
);
}
public
<
T
>
void
registerFunction
(
String
name
,
TableFunction
<
T
>
tableFunction
)
{
TypeInformation
<
T
>
typeInfo
=
UserDefinedFunctionHelper
.
getReturnTypeOfTableFunction
(
tableFunction
);
this
.
functionCatalog
.
registerTempSystemTableFunction
(
name
,
tableFunction
,
typeInfo
);
}
public
<
T
,
ACC
>
void
registerFunction
(
String
name
,
AggregateFunction
<
T
,
ACC
>
aggregateFunction
)
{
TypeInformation
<
T
>
typeInfo
=
UserDefinedFunctionHelper
.
getReturnTypeOfAggregateFunction
(
aggregateFunction
);
TypeInformation
<
ACC
>
accTypeInfo
=
UserDefinedFunctionHelper
.
getAccumulatorTypeOfAggregateFunction
(
aggregateFunction
);
this
.
functionCatalog
.
registerTempSystemAggregateFunction
(
name
,
aggregateFunction
,
typeInfo
,
accTypeInfo
);
}
public
<
T
,
ACC
>
void
registerFunction
(
String
name
,
TableAggregateFunction
<
T
,
ACC
>
tableAggregateFunction
)
{
TypeInformation
<
T
>
typeInfo
=
UserDefinedFunctionHelper
.
getReturnTypeOfAggregateFunction
(
tableAggregateFunction
);
TypeInformation
<
ACC
>
accTypeInfo
=
UserDefinedFunctionHelper
.
getAccumulatorTypeOfAggregateFunction
(
tableAggregateFunction
);
this
.
functionCatalog
.
registerTempSystemAggregateFunction
(
name
,
tableAggregateFunction
,
typeInfo
,
accTypeInfo
);
}
}
dlink-client/dlink-client-1.13/src/main/java/com/dlink/executor/custom/CustomTableResultImpl.java
0 → 100644
View file @
730e5822
package
com
.
dlink
.
executor
.
custom
;
import
org.apache.flink.annotation.Internal
;
import
org.apache.flink.core.execution.JobClient
;
import
org.apache.flink.table.api.*
;
import
org.apache.flink.table.catalog.Column
;
import
org.apache.flink.table.catalog.ResolvedSchema
;
import
org.apache.flink.table.utils.PrintUtils
;
import
org.apache.flink.types.Row
;
import
org.apache.flink.util.CloseableIterator
;
import
org.apache.flink.util.Preconditions
;
import
javax.annotation.Nullable
;
import
java.io.PrintWriter
;
import
java.time.ZoneId
;
import
java.util.*
;
import
java.util.concurrent.*
;
/**
* 定制TableResultImpl
* @author wenmo
* @since 2021/6/7 22:06
**/
@Internal
public
class
CustomTableResultImpl
implements
TableResult
{
public
static
final
TableResult
TABLE_RESULT_OK
;
private
final
JobClient
jobClient
;
private
final
ResolvedSchema
resolvedSchema
;
private
final
ResultKind
resultKind
;
private
final
CustomTableResultImpl
.
CloseableRowIteratorWrapper
data
;
private
final
CustomTableResultImpl
.
PrintStyle
printStyle
;
private
final
ZoneId
sessionTimeZone
;
private
CustomTableResultImpl
(
@Nullable
JobClient
jobClient
,
ResolvedSchema
resolvedSchema
,
ResultKind
resultKind
,
CloseableIterator
<
Row
>
data
,
CustomTableResultImpl
.
PrintStyle
printStyle
,
ZoneId
sessionTimeZone
)
{
this
.
jobClient
=
jobClient
;
this
.
resolvedSchema
=
(
ResolvedSchema
)
Preconditions
.
checkNotNull
(
resolvedSchema
,
"resolvedSchema should not be null"
);
this
.
resultKind
=
(
ResultKind
)
Preconditions
.
checkNotNull
(
resultKind
,
"resultKind should not be null"
);
Preconditions
.
checkNotNull
(
data
,
"data should not be null"
);
this
.
data
=
new
CustomTableResultImpl
.
CloseableRowIteratorWrapper
(
data
);
this
.
printStyle
=
(
CustomTableResultImpl
.
PrintStyle
)
Preconditions
.
checkNotNull
(
printStyle
,
"printStyle should not be null"
);
this
.
sessionTimeZone
=
(
ZoneId
)
Preconditions
.
checkNotNull
(
sessionTimeZone
,
"sessionTimeZone should not be null"
);
}
public
static
TableResult
buildTableResult
(
List
<
TableSchemaField
>
fields
,
List
<
Row
>
rows
){
Builder
builder
=
builder
().
resultKind
(
ResultKind
.
SUCCESS
);
if
(
fields
.
size
()>
0
)
{
//ResolvedSchema tableSchemaBuild = ResolvedSchema.of();
/*List<Column> columns = new ArrayList<>();
for (int i = 0; i < fields.size(); i++) {
columns.add(new TableColumn.PhysicalColumn(fields.get(i).getName(),fields.get(i).getType()));
}
builder.schema(tableSchemaBuild.build()).data(rows);*/
}
return
builder
.
build
();
}
public
Optional
<
JobClient
>
getJobClient
()
{
return
Optional
.
ofNullable
(
this
.
jobClient
);
}
public
void
await
()
throws
InterruptedException
,
ExecutionException
{
try
{
this
.
awaitInternal
(-
1L
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
TimeoutException
var2
)
{
;
}
}
public
void
await
(
long
timeout
,
TimeUnit
unit
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
this
.
awaitInternal
(
timeout
,
unit
);
}
private
void
awaitInternal
(
long
timeout
,
TimeUnit
unit
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
if
(
this
.
jobClient
!=
null
)
{
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
1
,
(
r
)
->
{
return
new
Thread
(
r
,
"TableResult-await-thread"
);
});
try
{
CompletableFuture
<
Void
>
future
=
CompletableFuture
.
runAsync
(()
->
{
while
(!
this
.
data
.
isFirstRowReady
())
{
try
{
Thread
.
sleep
(
100L
);
}
catch
(
InterruptedException
var2
)
{
throw
new
TableException
(
"Thread is interrupted"
);
}
}
},
executor
);
if
(
timeout
>=
0L
)
{
future
.
get
(
timeout
,
unit
);
}
else
{
future
.
get
();
}
}
finally
{
executor
.
shutdown
();
}
}
}
public
ResolvedSchema
getResolvedSchema
()
{
return
this
.
resolvedSchema
;
}
public
ResultKind
getResultKind
()
{
return
this
.
resultKind
;
}
public
CloseableIterator
<
Row
>
collect
()
{
return
this
.
data
;
}
public
void
print
()
{
Iterator
<
Row
>
it
=
this
.
collect
();
if
(
this
.
printStyle
instanceof
CustomTableResultImpl
.
TableauStyle
)
{
int
maxColumnWidth
=
((
CustomTableResultImpl
.
TableauStyle
)
this
.
printStyle
).
getMaxColumnWidth
();
String
nullColumn
=
((
CustomTableResultImpl
.
TableauStyle
)
this
.
printStyle
).
getNullColumn
();
boolean
deriveColumnWidthByType
=
((
CustomTableResultImpl
.
TableauStyle
)
this
.
printStyle
).
isDeriveColumnWidthByType
();
boolean
printRowKind
=
((
CustomTableResultImpl
.
TableauStyle
)
this
.
printStyle
).
isPrintRowKind
();
PrintUtils
.
printAsTableauForm
(
this
.
getResolvedSchema
(),
it
,
new
PrintWriter
(
System
.
out
),
maxColumnWidth
,
nullColumn
,
deriveColumnWidthByType
,
printRowKind
,
this
.
sessionTimeZone
);
}
else
{
if
(!(
this
.
printStyle
instanceof
CustomTableResultImpl
.
RawContentStyle
))
{
throw
new
TableException
(
"Unsupported print style: "
+
this
.
printStyle
);
}
while
(
it
.
hasNext
())
{
System
.
out
.
println
(
String
.
join
(
","
,
PrintUtils
.
rowToString
((
Row
)
it
.
next
(),
this
.
getResolvedSchema
(),
this
.
sessionTimeZone
)));
}
}
}
public
static
CustomTableResultImpl
.
Builder
builder
()
{
return
new
CustomTableResultImpl
.
Builder
();
}
static
{
TABLE_RESULT_OK
=
builder
().
resultKind
(
ResultKind
.
SUCCESS
).
schema
(
ResolvedSchema
.
of
(
new
Column
[]{
Column
.
physical
(
"result"
,
DataTypes
.
STRING
())})).
data
(
Collections
.
singletonList
(
Row
.
of
(
new
Object
[]{
"OK"
}))).
build
();
}
private
static
final
class
CloseableRowIteratorWrapper
implements
CloseableIterator
<
Row
>
{
private
final
CloseableIterator
<
Row
>
iterator
;
private
boolean
isFirstRowReady
;
private
CloseableRowIteratorWrapper
(
CloseableIterator
<
Row
>
iterator
)
{
this
.
isFirstRowReady
=
false
;
this
.
iterator
=
iterator
;
}
public
void
close
()
throws
Exception
{
this
.
iterator
.
close
();
}
public
boolean
hasNext
()
{
boolean
hasNext
=
this
.
iterator
.
hasNext
();
this
.
isFirstRowReady
=
this
.
isFirstRowReady
||
hasNext
;
return
hasNext
;
}
public
Row
next
()
{
Row
next
=
(
Row
)
this
.
iterator
.
next
();
this
.
isFirstRowReady
=
true
;
return
next
;
}
public
boolean
isFirstRowReady
()
{
return
this
.
isFirstRowReady
||
this
.
hasNext
();
}
}
private
static
final
class
RawContentStyle
implements
CustomTableResultImpl
.
PrintStyle
{
private
RawContentStyle
()
{
}
}
private
static
final
class
TableauStyle
implements
CustomTableResultImpl
.
PrintStyle
{
private
final
boolean
deriveColumnWidthByType
;
private
final
int
maxColumnWidth
;
private
final
String
nullColumn
;
private
final
boolean
printRowKind
;
private
TableauStyle
(
int
maxColumnWidth
,
String
nullColumn
,
boolean
deriveColumnWidthByType
,
boolean
printRowKind
)
{
this
.
deriveColumnWidthByType
=
deriveColumnWidthByType
;
this
.
maxColumnWidth
=
maxColumnWidth
;
this
.
nullColumn
=
nullColumn
;
this
.
printRowKind
=
printRowKind
;
}
public
boolean
isDeriveColumnWidthByType
()
{
return
this
.
deriveColumnWidthByType
;
}
int
getMaxColumnWidth
()
{
return
this
.
maxColumnWidth
;
}
String
getNullColumn
()
{
return
this
.
nullColumn
;
}
public
boolean
isPrintRowKind
()
{
return
this
.
printRowKind
;
}
}
public
interface
PrintStyle
{
static
CustomTableResultImpl
.
PrintStyle
tableau
(
int
maxColumnWidth
,
String
nullColumn
,
boolean
deriveColumnWidthByType
,
boolean
printRowKind
)
{
Preconditions
.
checkArgument
(
maxColumnWidth
>
0
,
"maxColumnWidth should be greater than 0"
);
Preconditions
.
checkNotNull
(
nullColumn
,
"nullColumn should not be null"
);
return
new
CustomTableResultImpl
.
TableauStyle
(
maxColumnWidth
,
nullColumn
,
deriveColumnWidthByType
,
printRowKind
);
}
static
CustomTableResultImpl
.
PrintStyle
rawContent
()
{
return
new
CustomTableResultImpl
.
RawContentStyle
();
}
}
public
static
class
Builder
{
private
JobClient
jobClient
;
private
ResolvedSchema
resolvedSchema
;
private
ResultKind
resultKind
;
private
CloseableIterator
<
Row
>
data
;
private
CustomTableResultImpl
.
PrintStyle
printStyle
;
private
ZoneId
sessionTimeZone
;
private
Builder
()
{
this
.
jobClient
=
null
;
this
.
resolvedSchema
=
null
;
this
.
resultKind
=
null
;
this
.
data
=
null
;
this
.
printStyle
=
CustomTableResultImpl
.
PrintStyle
.
tableau
(
2147483647
,
"(NULL)"
,
false
,
false
);
this
.
sessionTimeZone
=
ZoneId
.
of
(
"UTC"
);
}
public
CustomTableResultImpl
.
Builder
jobClient
(
JobClient
jobClient
)
{
this
.
jobClient
=
jobClient
;
return
this
;
}
public
CustomTableResultImpl
.
Builder
schema
(
ResolvedSchema
resolvedSchema
)
{
Preconditions
.
checkNotNull
(
resolvedSchema
,
"resolvedSchema should not be null"
);
this
.
resolvedSchema
=
resolvedSchema
;
return
this
;
}
public
CustomTableResultImpl
.
Builder
resultKind
(
ResultKind
resultKind
)
{
Preconditions
.
checkNotNull
(
resultKind
,
"resultKind should not be null"
);
this
.
resultKind
=
resultKind
;
return
this
;
}
public
CustomTableResultImpl
.
Builder
data
(
CloseableIterator
<
Row
>
rowIterator
)
{
Preconditions
.
checkNotNull
(
rowIterator
,
"rowIterator should not be null"
);
this
.
data
=
rowIterator
;
return
this
;
}
public
CustomTableResultImpl
.
Builder
data
(
List
<
Row
>
rowList
)
{
Preconditions
.
checkNotNull
(
rowList
,
"listRows should not be null"
);
this
.
data
=
CloseableIterator
.
adapterForIterator
(
rowList
.
iterator
());
return
this
;
}
public
CustomTableResultImpl
.
Builder
setPrintStyle
(
CustomTableResultImpl
.
PrintStyle
printStyle
)
{
Preconditions
.
checkNotNull
(
printStyle
,
"printStyle should not be null"
);
this
.
printStyle
=
printStyle
;
return
this
;
}
public
CustomTableResultImpl
.
Builder
setSessionTimeZone
(
ZoneId
sessionTimeZone
)
{
Preconditions
.
checkNotNull
(
sessionTimeZone
,
"sessionTimeZone should not be null"
);
this
.
sessionTimeZone
=
sessionTimeZone
;
return
this
;
}
public
TableResult
build
()
{
return
new
CustomTableResultImpl
(
this
.
jobClient
,
this
.
resolvedSchema
,
this
.
resultKind
,
this
.
data
,
this
.
printStyle
,
this
.
sessionTimeZone
);
}
}
}
\ No newline at end of file
dlink-client/dlink-client-1.13/src/main/java/com/dlink/executor/custom/SqlManager.java
0 → 100644
View file @
730e5822
package
com
.
dlink
.
executor
.
custom
;
import
org.apache.flink.annotation.Internal
;
import
org.apache.flink.table.api.DataTypes
;
import
org.apache.flink.table.api.ExpressionParserException
;
import
org.apache.flink.table.api.Table
;
import
org.apache.flink.table.api.TableResult
;
import
org.apache.flink.table.catalog.exceptions.CatalogException
;
import
org.apache.flink.types.Row
;
import
org.apache.flink.util.StringUtils
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
java
.
lang
.
String
.
format
;
import
static
org
.
apache
.
flink
.
util
.
Preconditions
.
checkArgument
;
import
static
org
.
apache
.
flink
.
util
.
Preconditions
.
checkNotNull
;
/**
* Flink Sql Fragment Manager
* @author wenmo
* @since 2021/6/7 22:06
**/
@Internal
public
final
class
SqlManager
{
private
Map
<
String
,
String
>
sqlFragments
;
static
final
String
SHOW_FRAGMENTS
=
"SHOW FRAGMENTS"
;
public
SqlManager
()
{
sqlFragments
=
new
HashMap
<>();
}
/**
* Get names of sql fragments loaded.
*
* @return a list of names of sql fragments loaded
*/
public
List
<
String
>
listSqlFragments
()
{
return
new
ArrayList
<>(
sqlFragments
.
keySet
());
}
/**
* Registers a fragment of sql under the given name. The sql fragment name must be unique.
*
* @param sqlFragmentName name under which to register the given sql fragment
* @param sqlFragment a fragment of sql to register
* @throws CatalogException if the registration of the sql fragment under the given name failed.
* But at the moment, with CatalogException, not SqlException
*/
public
void
registerSqlFragment
(
String
sqlFragmentName
,
String
sqlFragment
)
{
checkArgument
(
!
StringUtils
.
isNullOrWhitespaceOnly
(
sqlFragmentName
),
"sql fragment name cannot be null or empty."
);
checkNotNull
(
sqlFragment
,
"sql fragment cannot be null"
);
if
(
sqlFragments
.
containsKey
(
sqlFragmentName
))
{
throw
new
CatalogException
(
format
(
"The fragment of sql %s already exists."
,
sqlFragmentName
));
}
sqlFragments
.
put
(
sqlFragmentName
,
sqlFragment
);
}
/**
* Unregisters a fragment of sql under the given name. The sql fragment name must be existed.
*
* @param sqlFragmentName name under which to unregister the given sql fragment.
* @param ignoreIfNotExists If false exception will be thrown if the fragment of sql to be
* altered does not exist.
* @throws CatalogException if the unregistration of the sql fragment under the given name
* failed. But at the moment, with CatalogException, not SqlException
*/
public
void
unregisterSqlFragment
(
String
sqlFragmentName
,
boolean
ignoreIfNotExists
)
{
checkArgument
(
!
StringUtils
.
isNullOrWhitespaceOnly
(
sqlFragmentName
),
"sql fragmentName name cannot be null or empty."
);
if
(
sqlFragments
.
containsKey
(
sqlFragmentName
))
{
sqlFragments
.
remove
(
sqlFragmentName
);
}
else
if
(!
ignoreIfNotExists
)
{
throw
new
CatalogException
(
format
(
"The fragment of sql %s does not exist."
,
sqlFragmentName
));
}
}
/**
* Get a fragment of sql under the given name. The sql fragment name must be existed.
*
* @param sqlFragmentName name under which to unregister the given sql fragment.
* @throws CatalogException if the unregistration of the sql fragment under the given name
* failed. But at the moment, with CatalogException, not SqlException
*/
public
String
getSqlFragment
(
String
sqlFragmentName
)
{
checkArgument
(
!
StringUtils
.
isNullOrWhitespaceOnly
(
sqlFragmentName
),
"sql fragmentName name cannot be null or empty."
);
if
(
sqlFragments
.
containsKey
(
sqlFragmentName
))
{
return
sqlFragments
.
get
(
sqlFragmentName
);
}
else
{
throw
new
CatalogException
(
format
(
"The fragment of sql %s does not exist."
,
sqlFragmentName
));
}
}
/**
* Get a fragment of sql under the given name. The sql fragment name must be existed.
*
* @throws CatalogException if the unregistration of the sql fragment under the given name
* failed. But at the moment, with CatalogException, not SqlException
*/
public
Map
<
String
,
String
>
getSqlFragment
()
{
return
sqlFragments
;
}
public
TableResult
getSqlFragments
()
{
List
<
Row
>
rows
=
new
ArrayList
<>();
for
(
String
key
:
sqlFragments
.
keySet
())
{
rows
.
add
(
Row
.
of
(
key
));
}
return
CustomTableResultImpl
.
buildTableResult
(
new
ArrayList
<>(
Arrays
.
asList
(
new
TableSchemaField
(
"sql fragment name"
,
DataTypes
.
STRING
()))),
rows
);
}
public
Iterator
getSqlFragmentsIterator
()
{
return
sqlFragments
.
entrySet
().
iterator
();
}
public
Table
getSqlFragmentsTable
(
CustomTableEnvironmentImpl
environment
)
{
List
<
String
>
keys
=
new
ArrayList
<>();
for
(
String
key
:
sqlFragments
.
keySet
())
{
keys
.
add
(
key
);
}
return
environment
.
fromValues
(
keys
);
}
public
boolean
checkShowFragments
(
String
sql
){
return
SHOW_FRAGMENTS
.
equals
(
sql
.
trim
().
toUpperCase
());
}
/**
* Parse some variables under the given sql.
*
* @param statement A sql will be parsed.
* @throws ExpressionParserException if the name of the variable under the given sql failed.
*/
public
String
parseVariable
(
String
statement
)
{
if
(
statement
==
null
||
""
.
equals
(
statement
))
{
return
statement
;
}
String
[]
strs
=
statement
.
split
(
";"
);
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
strs
.
length
;
i
++)
{
String
str
=
strs
[
i
].
trim
();
if
(
str
.
length
()
==
0
)
{
continue
;
}
if
(
str
.
contains
(
":="
))
{
String
[]
strs2
=
str
.
split
(
":="
);
if
(
strs2
.
length
>=
2
)
{
if
(
strs2
[
0
].
length
()
==
0
)
{
throw
new
ExpressionParserException
(
"Illegal variable name."
);
}
String
valueString
=
str
.
substring
(
str
.
indexOf
(
":="
)
+
2
);
this
.
registerSqlFragment
(
strs2
[
0
],
replaceVariable
(
valueString
));
}
else
{
throw
new
ExpressionParserException
(
"Illegal variable definition."
);
}
}
else
{
sb
.
append
(
replaceVariable
(
str
));
}
}
return
sb
.
toString
();
}
/**
* Replace some variables under the given sql.
*
* @param statement A sql will be replaced.
*/
private
String
replaceVariable
(
String
statement
)
{
String
pattern
=
"\\$\\{(.+?)\\}"
;
Pattern
p
=
Pattern
.
compile
(
pattern
);
Matcher
m
=
p
.
matcher
(
statement
);
StringBuffer
sb
=
new
StringBuffer
();
while
(
m
.
find
())
{
String
key
=
m
.
group
(
1
);
String
value
=
this
.
getSqlFragment
(
key
);
m
.
appendReplacement
(
sb
,
value
==
null
?
""
:
value
);
}
m
.
appendTail
(
sb
);
return
sb
.
toString
();
}
}
dlink-client/dlink-client-1.13/src/main/java/com/dlink/executor/custom/TableSchemaField.java
0 → 100644
View file @
730e5822
package
com
.
dlink
.
executor
.
custom
;
import
org.apache.flink.table.types.DataType
;
/**
* @author wenmo
* @since 2021/6/7 22:06
**/
public
class
TableSchemaField
{
private
String
name
;
private
DataType
type
;
public
TableSchemaField
(
String
name
,
DataType
type
)
{
this
.
name
=
name
;
this
.
type
=
type
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
DataType
getType
()
{
return
type
;
}
public
void
setType
(
DataType
type
)
{
this
.
type
=
type
;
}
}
dlink-client/dlink-client-1.13/src/main/java/com/dlink/result/SqlExplainResult.java
0 → 100644
View file @
730e5822
package
com
.
dlink
.
result
;
import
java.util.Date
;
/**
* 解释结果
*
* @author wenmo
* @since 2021/6/7 22:06
**/
public
class
SqlExplainResult
{
private
Integer
index
;
private
String
type
;
private
String
sql
;
private
String
parse
;
private
String
explain
;
private
String
error
;
private
boolean
parseTrue
;
private
boolean
explainTrue
;
private
Date
explainTime
;
public
Integer
getIndex
()
{
return
index
;
}
public
void
setIndex
(
Integer
index
)
{
this
.
index
=
index
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getSql
()
{
return
sql
;
}
public
void
setSql
(
String
sql
)
{
this
.
sql
=
sql
;
}
public
String
getParse
()
{
return
parse
;
}
public
void
setParse
(
String
parse
)
{
this
.
parse
=
parse
;
}
public
String
getExplain
()
{
return
explain
;
}
public
void
setExplain
(
String
explain
)
{
this
.
explain
=
explain
;
}
public
String
getError
()
{
return
error
;
}
public
void
setError
(
String
error
)
{
this
.
error
=
error
;
}
public
boolean
isParseTrue
()
{
return
parseTrue
;
}
public
void
setParseTrue
(
boolean
parseTrue
)
{
this
.
parseTrue
=
parseTrue
;
}
public
boolean
isExplainTrue
()
{
return
explainTrue
;
}
public
void
setExplainTrue
(
boolean
explainTrue
)
{
this
.
explainTrue
=
explainTrue
;
}
public
Date
getExplainTime
()
{
return
explainTime
;
}
public
void
setExplainTime
(
Date
explainTime
)
{
this
.
explainTime
=
explainTime
;
}
@Override
public
String
toString
()
{
return
"SqlExplainRecord{"
+
"index="
+
index
+
", type='"
+
type
+
'\''
+
", sql='"
+
sql
+
'\''
+
", parse='"
+
parse
+
'\''
+
", explain='"
+
explain
+
'\''
+
", error='"
+
error
+
'\''
+
", parseTrue="
+
parseTrue
+
", explainTrue="
+
explainTrue
+
", explainTime="
+
explainTime
+
'}'
;
}
}
dlink-client/dlink-client-1.13/src/main/java/org/apache/flink/streaming/api/graph/JSONGenerator.java
0 → 100644
View file @
730e5822
/*
* 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
.
apache
.
flink
.
streaming
.
api
.
graph
;
import
org.apache.flink.annotation.Internal
;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper
;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode
;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode
;
import
java.util.*
;
/** Helper class for generating a JSON representation from a {@link StreamGraph}. */
@Internal
public
class
JSONGenerator
{
public
static
final
String
STEPS
=
"step_function"
;
public
static
final
String
ID
=
"id"
;
public
static
final
String
SIDE
=
"side"
;
public
static
final
String
SHIP_STRATEGY
=
"ship_strategy"
;
public
static
final
String
PREDECESSORS
=
"predecessors"
;
public
static
final
String
TYPE
=
"type"
;
public
static
final
String
PACT
=
"pact"
;
public
static
final
String
CONTENTS
=
"contents"
;
public
static
final
String
PARALLELISM
=
"parallelism"
;
private
StreamGraph
streamGraph
;
private
final
ObjectMapper
mapper
=
new
ObjectMapper
();
public
JSONGenerator
(
StreamGraph
streamGraph
)
{
this
.
streamGraph
=
streamGraph
;
}
public
String
getJSON
()
{
return
getJSONNode
().
toPrettyString
();
}
public
ObjectNode
getJSONNode
()
{
ObjectNode
json
=
mapper
.
createObjectNode
();
ArrayNode
nodes
=
mapper
.
createArrayNode
();
json
.
put
(
"nodes"
,
nodes
);
List
<
Integer
>
operatorIDs
=
new
ArrayList
<>(
streamGraph
.
getVertexIDs
());
Comparator
<
Integer
>
operatorIDComparator
=
Comparator
.
comparingInt
(
(
Integer
id
)
->
streamGraph
.
getSinkIDs
().
contains
(
id
)
?
1
:
0
)
.
thenComparingInt
(
id
->
id
);
operatorIDs
.
sort
(
operatorIDComparator
);
visit
(
nodes
,
operatorIDs
,
new
HashMap
<>());
return
json
;
}
private
void
visit
(
ArrayNode
jsonArray
,
List
<
Integer
>
toVisit
,
Map
<
Integer
,
Integer
>
edgeRemapings
)
{
Integer
vertexID
=
toVisit
.
get
(
0
);
StreamNode
vertex
=
streamGraph
.
getStreamNode
(
vertexID
);
if
(
streamGraph
.
getSourceIDs
().
contains
(
vertexID
)
||
Collections
.
disjoint
(
vertex
.
getInEdges
(),
toVisit
))
{
ObjectNode
node
=
mapper
.
createObjectNode
();
decorateNode
(
vertexID
,
node
);
if
(!
streamGraph
.
getSourceIDs
().
contains
(
vertexID
))
{
ArrayNode
inputs
=
mapper
.
createArrayNode
();
node
.
put
(
PREDECESSORS
,
inputs
);
for
(
StreamEdge
inEdge
:
vertex
.
getInEdges
())
{
int
inputID
=
inEdge
.
getSourceId
();
Integer
mappedID
=
(
edgeRemapings
.
keySet
().
contains
(
inputID
))
?
edgeRemapings
.
get
(
inputID
)
:
inputID
;
decorateEdge
(
inputs
,
inEdge
,
mappedID
);
}
}
jsonArray
.
add
(
node
);
toVisit
.
remove
(
vertexID
);
}
else
{
Integer
iterationHead
=
-
1
;
for
(
StreamEdge
inEdge
:
vertex
.
getInEdges
())
{
int
operator
=
inEdge
.
getSourceId
();
if
(
streamGraph
.
vertexIDtoLoopTimeout
.
containsKey
(
operator
))
{
iterationHead
=
operator
;
}
}
ObjectNode
obj
=
mapper
.
createObjectNode
();
ArrayNode
iterationSteps
=
mapper
.
createArrayNode
();
obj
.
put
(
STEPS
,
iterationSteps
);
obj
.
put
(
ID
,
iterationHead
);
obj
.
put
(
PACT
,
"IterativeDataStream"
);
obj
.
put
(
PARALLELISM
,
streamGraph
.
getStreamNode
(
iterationHead
).
getParallelism
());
obj
.
put
(
CONTENTS
,
"Stream Iteration"
);
ArrayNode
iterationInputs
=
mapper
.
createArrayNode
();
obj
.
put
(
PREDECESSORS
,
iterationInputs
);
toVisit
.
remove
(
iterationHead
);
visitIteration
(
iterationSteps
,
toVisit
,
iterationHead
,
edgeRemapings
,
iterationInputs
);
jsonArray
.
add
(
obj
);
}
if
(!
toVisit
.
isEmpty
())
{
visit
(
jsonArray
,
toVisit
,
edgeRemapings
);
}
}
private
void
visitIteration
(
ArrayNode
jsonArray
,
List
<
Integer
>
toVisit
,
int
headId
,
Map
<
Integer
,
Integer
>
edgeRemapings
,
ArrayNode
iterationInEdges
)
{
Integer
vertexID
=
toVisit
.
get
(
0
);
StreamNode
vertex
=
streamGraph
.
getStreamNode
(
vertexID
);
toVisit
.
remove
(
vertexID
);
// Ignoring head and tail to avoid redundancy
if
(!
streamGraph
.
vertexIDtoLoopTimeout
.
containsKey
(
vertexID
))
{
ObjectNode
obj
=
mapper
.
createObjectNode
();
jsonArray
.
add
(
obj
);
decorateNode
(
vertexID
,
obj
);
ArrayNode
inEdges
=
mapper
.
createArrayNode
();
obj
.
put
(
PREDECESSORS
,
inEdges
);
for
(
StreamEdge
inEdge
:
vertex
.
getInEdges
())
{
int
inputID
=
inEdge
.
getSourceId
();
if
(
edgeRemapings
.
keySet
().
contains
(
inputID
))
{
decorateEdge
(
inEdges
,
inEdge
,
inputID
);
}
else
if
(!
streamGraph
.
vertexIDtoLoopTimeout
.
containsKey
(
inputID
))
{
decorateEdge
(
iterationInEdges
,
inEdge
,
inputID
);
}
}
edgeRemapings
.
put
(
vertexID
,
headId
);
visitIteration
(
jsonArray
,
toVisit
,
headId
,
edgeRemapings
,
iterationInEdges
);
}
}
private
void
decorateEdge
(
ArrayNode
inputArray
,
StreamEdge
inEdge
,
int
mappedInputID
)
{
ObjectNode
input
=
mapper
.
createObjectNode
();
inputArray
.
add
(
input
);
input
.
put
(
ID
,
mappedInputID
);
input
.
put
(
SHIP_STRATEGY
,
inEdge
.
getPartitioner
().
toString
());
input
.
put
(
SIDE
,
(
inputArray
.
size
()
==
0
)
?
"first"
:
"second"
);
}
private
void
decorateNode
(
Integer
vertexID
,
ObjectNode
node
)
{
StreamNode
vertex
=
streamGraph
.
getStreamNode
(
vertexID
);
node
.
put
(
ID
,
vertexID
);
node
.
put
(
TYPE
,
vertex
.
getOperatorName
());
if
(
streamGraph
.
getSourceIDs
().
contains
(
vertexID
))
{
node
.
put
(
PACT
,
"Data Source"
);
}
else
if
(
streamGraph
.
getSinkIDs
().
contains
(
vertexID
))
{
node
.
put
(
PACT
,
"Data Sink"
);
}
else
{
node
.
put
(
PACT
,
"Operator"
);
}
node
.
put
(
CONTENTS
,
vertex
.
getOperatorName
());
node
.
put
(
PARALLELISM
,
streamGraph
.
getStreamNode
(
vertexID
).
getParallelism
());
}
}
dlink-client/pom.xml
View file @
730e5822
...
...
@@ -11,6 +11,7 @@
<packaging>
pom
</packaging>
<modules>
<module>
dlink-client-1.12
</module>
<module>
dlink-client-1.13
</module>
</modules>
<artifactId>
dlink-client
</artifactId>
</project>
\ No newline at end of file
dlink-core/pom.xml
View file @
730e5822
...
...
@@ -31,17 +31,17 @@
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-client-1.12
</artifactId>
<
scope>
provided
</scope
>
<
!--<scope>provided</scope>--
>
</dependency>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-connector-jdbc
</artifactId>
<
scope>
provided
</scope
>
<
!--<scope>provided</scope>--
>
</dependency>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-function
</artifactId>
<
scope>
provided
</scope
>
<
!--<scope>provided</scope>--
>
</dependency>
</dependencies>
</project>
\ No newline at end of file
dlink-core/src/main/java/com/dlink/job/JobManager.java
View file @
730e5822
...
...
@@ -32,11 +32,16 @@ public class JobManager {
private
Integer
port
;
private
String
sessionId
;
private
Integer
maxRowNum
=
100
;
private
ExecutorSetting
executorSetting
;
public
JobManager
()
{
}
public
JobManager
(
String
host
)
{
public
JobManager
(
ExecutorSetting
executorSetting
)
{
this
.
executorSetting
=
executorSetting
;
}
public
JobManager
(
String
host
,
ExecutorSetting
executorSetting
)
{
if
(
host
!=
null
)
{
String
[]
strs
=
host
.
split
(
":"
);
if
(
strs
.
length
>=
2
)
{
...
...
@@ -46,10 +51,11 @@ public class JobManager {
this
.
flinkHost
=
strs
[
0
];
this
.
port
=
8081
;
}
this
.
executorSetting
=
executorSetting
;
}
}
public
JobManager
(
String
host
,
String
sessionId
,
Integer
maxRowNum
)
{
public
JobManager
(
String
host
,
String
sessionId
,
Integer
maxRowNum
,
ExecutorSetting
executorSetting
)
{
if
(
host
!=
null
)
{
String
[]
strs
=
host
.
split
(
":"
);
if
(
strs
.
length
>=
2
)
{
...
...
@@ -57,11 +63,12 @@ public class JobManager {
this
.
port
=
Integer
.
parseInt
(
strs
[
1
]);
}
else
{
this
.
flinkHost
=
strs
[
0
];
this
.
port
=
8081
;
this
.
port
=
FlinkConstant
.
PORT
;
}
}
this
.
sessionId
=
sessionId
;
this
.
maxRowNum
=
maxRowNum
;
this
.
executorSetting
=
executorSetting
;
}
public
JobManager
(
String
flinkHost
,
Integer
port
)
{
...
...
@@ -76,23 +83,45 @@ public class JobManager {
this
.
port
=
port
;
}
public
RunResult
execute
(
String
statement
,
ExecutorSetting
executorSetting
)
{
RunResult
runResult
=
new
RunResult
(
sessionId
,
statement
,
flinkHost
,
port
,
executorSetting
,
executorSetting
.
getJobName
());
Executor
executor
=
null
;
private
boolean
checkSession
(){
if
(
sessionId
!=
null
&&!
""
.
equals
(
sessionId
)){
String
[]
strs
=
sessionId
.
split
(
"_"
);
if
(
strs
.
length
>
1
&&!
""
.
equals
(
strs
[
1
])){
return
true
;
}
}
return
false
;
}
private
Executor
createExecutor
(){
if
(
executorSetting
.
isRemote
())
{
return
Executor
.
build
(
new
EnvironmentSetting
(
flinkHost
,
port
),
executorSetting
);
}
else
{
return
Executor
.
build
(
null
,
executorSetting
);
}
}
private
Executor
createExecutorWithSession
(){
Executor
executor
;
if
(
checkSession
()){
ExecutorEntity
executorEntity
=
SessionPool
.
get
(
sessionId
);
if
(
executorEntity
!=
null
)
{
executor
=
executorEntity
.
getExecutor
();
}
else
{
if
(
executorSetting
.
isRemote
())
{
executor
=
Executor
.
build
(
new
EnvironmentSetting
(
flinkHost
,
FlinkConstant
.
PORT
),
executorSetting
);
}
else
{
executor
=
Executor
.
build
(
null
,
executorSetting
);
}
executor
=
createExecutor
();
SessionPool
.
push
(
new
ExecutorEntity
(
sessionId
,
executor
));
}
}
else
{
executor
=
createExecutor
();
}
return
executor
;
}
public
RunResult
execute
(
String
statement
)
{
RunResult
runResult
=
new
RunResult
(
sessionId
,
statement
,
flinkHost
,
port
,
executorSetting
,
executorSetting
.
getJobName
());
Executor
executor
=
createExecutorWithSession
();
String
[]
Statements
=
statement
.
split
(
";"
);
int
currentIndex
=
0
;
//当前只支持对 show select的操作的结果的数据查询 后期需要可添加
try
{
for
(
String
item
:
Statements
)
{
currentIndex
++;
...
...
@@ -133,24 +162,20 @@ public class JobManager {
return
runResult
;
}
public
SubmitResult
submit
(
String
statement
,
ExecutorSetting
executorSetting
)
{
public
SubmitResult
submit
(
String
statement
)
{
if
(
statement
==
null
||
""
.
equals
(
statement
))
{
return
SubmitResult
.
error
(
"FlinkSql语句不存在"
);
}
String
[]
statements
=
statement
.
split
(
FlinkSQLConstant
.
SEPARATOR
);
return
submit
(
Arrays
.
asList
(
statements
)
,
executorSetting
);
return
submit
(
Arrays
.
asList
(
statements
));
}
public
SubmitResult
submit
(
List
<
String
>
sqlList
,
ExecutorSetting
executorSetting
)
{
public
SubmitResult
submit
(
List
<
String
>
sqlList
)
{
SubmitResult
result
=
new
SubmitResult
(
sessionId
,
sqlList
,
flinkHost
,
executorSetting
.
getJobName
());
int
currentIndex
=
0
;
try
{
if
(
sqlList
!=
null
&&
sqlList
.
size
()
>
0
)
{
EnvironmentSetting
environmentSetting
=
null
;
if
(
executorSetting
.
isRemote
())
{
environmentSetting
=
new
EnvironmentSetting
(
flinkHost
,
port
);
}
Executor
executor
=
Executor
.
build
(
environmentSetting
,
executorSetting
);
Executor
executor
=
createExecutor
();
for
(
String
sqlText
:
sqlList
)
{
currentIndex
++;
String
operationType
=
Operations
.
getOperationType
(
sqlText
);
...
...
dlink-core/src/test/java/com/dlink/core/JobManagerTest.java
View file @
730e5822
...
...
@@ -20,7 +20,8 @@ public class JobManagerTest {
@Test
public
void
submitJobTest2
(){
JobManager
jobManager
=
new
JobManager
(
"192.168.123.157"
,
8081
,
"test2"
,
100
);
ExecutorSetting
setting
=
new
ExecutorSetting
(
Executor
.
REMOTE
);
JobManager
jobManager
=
new
JobManager
(
"192.168.123.157:8081"
,
"test2"
,
100
,
setting
);
String
sql1
=
"CREATE TABLE student (\n"
+
" sid INT,\n"
+
" name STRING,\n"
+
...
...
@@ -48,14 +49,15 @@ public class JobManagerTest {
sqls
.
add
(
sql1
);
sqls
.
add
(
sql2
);
sqls
.
add
(
sql3
);
ExecutorSetting
setting
=
new
ExecutorSetting
(
Executor
.
REMOTE
);
SubmitResult
result
=
jobManager
.
submit
(
sqls
,
setting
);
SubmitResult
result
=
jobManager
.
submit
(
sqls
);
System
.
out
.
println
(
result
.
isSuccess
());
}
@Test
public
void
executeJobTest
(){
JobManager
jobManager
=
new
JobManager
(
"192.168.123.157"
,
8081
,
"test2"
,
100
);
ExecutorSetting
setting
=
new
ExecutorSetting
(
Executor
.
REMOTE
,
0
,
1
,
false
,
null
);
JobManager
jobManager
=
new
JobManager
(
"192.168.123.157:8081"
,
"test2"
,
100
,
setting
);
String
sql1
=
"CREATE TABLE student (\n"
+
" sid INT,\n"
+
" name STRING,\n"
+
...
...
@@ -84,8 +86,7 @@ public class JobManagerTest {
sqls
.
add
(
sql2
);
sqls
.
add
(
sql3
);
String
sql
=
sql1
+
sql2
+
sql3
;
ExecutorSetting
setting
=
new
ExecutorSetting
(
Executor
.
REMOTE
,
0
,
1
,
false
,
null
);
RunResult
result
=
jobManager
.
execute
(
sql
,
setting
);
RunResult
result
=
jobManager
.
execute
(
sql
);
System
.
out
.
println
(
result
.
isSuccess
());
}
}
dlink-web/src/components/Studio/StudioMenu/index.tsx
View file @
730e5822
...
...
@@ -22,7 +22,7 @@ const menu = (
const
StudioMenu
=
(
props
:
any
)
=>
{
const
{
tabs
,
current
,
currentPath
,
form
,
dispatch
,
monaco
}
=
props
;
const
{
tabs
,
current
,
currentPath
,
form
,
dispatch
}
=
props
;
const
execute
=
()
=>
{
let
selection
=
current
.
monaco
.
current
.
editor
.
getSelection
();
...
...
dlink-web/src/components/Studio/StudioSetting/index.tsx
View file @
730e5822
...
...
@@ -47,12 +47,13 @@ const StudioSetting = (props: any) => {
let
newTabs
=
tabs
;
for
(
let
i
=
0
;
i
<
newTabs
.
panes
.
length
;
i
++
){
if
(
newTabs
.
panes
[
i
].
key
==
newTabs
.
activeKey
){
newTabs
.
panes
[
i
].
task
=
{
...
all
}
;
for
(
let
key
in
change
)
{
newTabs
.
panes
[
i
].
task
[
key
]
=
change
[
key
];
}
break
;
}
}
dispatch
&&
dispatch
({
type
:
"Studio/saveTabs"
,
payload
:
newTabs
,
...
...
@@ -144,7 +145,8 @@ const StudioSetting = (props: any) => {
className=
{
styles
.
form_item
}
>
<
Select
placeholder=
"选择会话"
defaultValue=
'admin'
// defaultValue='admin'
allowClear
dropdownRender=
{
menu
=>
(
<
div
>
{
menu
}
...
...
dlink-web/src/components/Studio/StudioTree/index.tsx
View file @
730e5822
...
...
@@ -136,13 +136,14 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
closable
:
true
,
path
:
node
.
path
,
task
:{
session
:
'
admin
'
,
session
:
''
,
maxRowNum
:
100
,
...
result
.
datas
},
console
:{
result
:[],
}
},
monaco
:
{},
};
newTabs
.
activeKey
=
node
.
taskId
;
newTabs
.
panes
.
push
(
newPane
);
...
...
dlink-web/src/pages/FlinkSqlStudio/model.ts
View file @
730e5822
...
...
@@ -124,7 +124,7 @@ const Model: ModelType = {
fragment
:
true
,
clusterId
:
0
,
maxRowNum
:
100
,
session
:
'
admin
'
,
session
:
''
,
alias
:
'草稿'
,
},
console
:{
...
...
@@ -149,7 +149,7 @@ const Model: ModelType = {
parallelism
:
1
,
fragment
:
true
,
clusterId
:
'0'
,
session
:
'
admin
'
,
session
:
''
,
maxRowNum
:
100
,
alias
:
'草稿'
,
},
...
...
@@ -159,7 +159,7 @@ const Model: ModelType = {
monaco
:
{},
}],
},
session
:[
'admin'
],
session
:[],
rightClickMenu
:
false
},
...
...
dlink-web/src/pages/Welcome.tsx
View file @
730e5822
...
...
@@ -205,6 +205,15 @@ export default (): React.ReactNode => {
<
li
>
<
Link
href=
""
>
增加了新增作业自动定位及打开选项卡的功能
</
Link
>
</
li
>
<
li
>
<
Link
href=
""
>
增加了在不选择会话值时自动禁用会话的功能
</
Link
>
</
li
>
<
li
>
<
Link
href=
""
>
解决了在修改配置后异步提交任务会将作业识别为草稿的问题
</
Link
>
</
li
>
<
li
>
<
Link
href=
""
>
扩展了 Flink Client 1.13
</
Link
>
</
li
>
</
ul
>
</
Paragraph
>
</
Timeline
.
Item
>
...
...
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