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
578126ce
Unverified
Commit
578126ce
authored
Oct 09, 2023
by
ZackYoung
Committed by
GitHub
Oct 09, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix][Flink SQL] Fix flink sql use ctas syntax (#2365)
* fix_ctas * fix_ctas
parent
91743916
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
126 additions
and
7 deletions
+126
-7
EnvInit.java
dinky-admin/src/main/java/org/dinky/init/EnvInit.java
+2
-2
CustomTableEnvironmentImpl.java
...n/java/org/dinky/executor/CustomTableEnvironmentImpl.java
+13
-0
CustomTableEnvironmentImpl.java
...n/java/org/dinky/executor/CustomTableEnvironmentImpl.java
+13
-0
CustomTableEnvironmentImpl.java
...n/java/org/dinky/executor/CustomTableEnvironmentImpl.java
+16
-0
CustomTableEnvironmentImpl.java
...n/java/org/dinky/executor/CustomTableEnvironmentImpl.java
+24
-1
CustomTableEnvironmentImpl.java
...n/java/org/dinky/executor/CustomTableEnvironmentImpl.java
+19
-1
CustomTableEnvironment.java
.../main/java/org/dinky/executor/CustomTableEnvironment.java
+3
-0
Explainer.java
dinky-core/src/main/java/org/dinky/explainer/Explainer.java
+28
-1
JobManager.java
dinky-core/src/main/java/org/dinky/job/JobManager.java
+8
-2
No files found.
dinky-admin/src/main/java/org/dinky/init/EnvInit.java
View file @
578126ce
...
...
@@ -47,8 +47,8 @@ public class EnvInit implements ApplicationRunner {
+
"Application 'Dinky' is running! Access URLs:\n\t"
+
"Local: \t\thttp://localhost:{}\n\t"
+
"External: \thttp://{}:{}\n\t"
+
"Doc: \thttp://{}:{}/doc.html\n"
+
"Druid Monitor: \thttp://{}:{}/druid/index.html\n"
+
"Doc: \thttp://{}:{}/doc.html\n
\t
"
+
"Druid Monitor: \thttp://{}:{}/druid/index.html\n
\t
"
+
"Actuator: \thttp://{}:{}/actuator\n"
+
"----------------------------------------------------------"
,
port
,
...
...
dinky-client/dinky-client-1.13/src/main/java/org/dinky/executor/CustomTableEnvironmentImpl.java
View file @
578126ce
...
...
@@ -65,6 +65,8 @@ import org.apache.flink.table.operations.Operation;
import
org.apache.flink.table.operations.QueryOperation
;
import
org.apache.flink.table.operations.command.ResetOperation
;
import
org.apache.flink.table.operations.command.SetOperation
;
import
org.apache.flink.table.operations.ddl.CreateTableASOperation
;
import
org.apache.flink.table.operations.ddl.CreateTableOperation
;
import
org.apache.flink.table.planner.delegation.ExecutorBase
;
import
org.apache.flink.table.planner.plan.optimize.program.FlinkChainedProgram
;
import
org.apache.flink.table.planner.utils.ExecutorUtils
;
...
...
@@ -83,6 +85,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ReflectUtil
;
/**
...
...
@@ -382,6 +385,16 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
createTemporaryView
(
s
,
fromChangelogStream
(
dataStream
));
}
@Override
public
void
executeCTAS
(
Operation
operation
)
{
if
(
operation
instanceof
CreateTableASOperation
)
{
CreateTableASOperation
createTableASOperation
=
(
CreateTableASOperation
)
operation
;
CreateTableOperation
createTableOperation
=
createTableASOperation
.
getCreateTableOperation
();
executeInternal
(
createTableOperation
);
getPlanner
().
translate
(
CollUtil
.
newArrayList
(
createTableASOperation
.
getInsertOperation
()));
}
}
@Override
public
<
T
>
void
createTemporaryView
(
String
path
,
DataStream
<
T
>
dataStream
,
Expression
...
fields
)
{
this
.
createTemporaryView
(
path
,
this
.
fromDataStream
(
dataStream
,
fields
));
...
...
dinky-client/dinky-client-1.14/src/main/java/org/dinky/executor/CustomTableEnvironmentImpl.java
View file @
578126ce
...
...
@@ -65,6 +65,8 @@ import org.apache.flink.table.operations.Operation;
import
org.apache.flink.table.operations.QueryOperation
;
import
org.apache.flink.table.operations.command.ResetOperation
;
import
org.apache.flink.table.operations.command.SetOperation
;
import
org.apache.flink.table.operations.ddl.CreateTableASOperation
;
import
org.apache.flink.table.operations.ddl.CreateTableOperation
;
import
org.apache.flink.table.planner.delegation.DefaultExecutor
;
import
org.apache.flink.table.planner.plan.optimize.program.FlinkChainedProgram
;
import
org.apache.flink.table.typeutils.FieldInfoUtils
;
...
...
@@ -82,6 +84,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ReflectUtil
;
/**
...
...
@@ -372,6 +375,16 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
createTemporaryView
(
s
,
fromChangelogStream
(
dataStream
));
}
@Override
public
void
executeCTAS
(
Operation
operation
)
{
if
(
operation
instanceof
CreateTableASOperation
)
{
CreateTableASOperation
createTableASOperation
=
(
CreateTableASOperation
)
operation
;
CreateTableOperation
createTableOperation
=
createTableASOperation
.
getCreateTableOperation
();
executeInternal
(
createTableOperation
);
getPlanner
().
translate
(
CollUtil
.
newArrayList
(
createTableASOperation
.
getInsertOperation
()));
}
}
@Override
public
<
T
>
void
createTemporaryView
(
String
path
,
DataStream
<
T
>
dataStream
,
Expression
...
fields
)
{
createTemporaryView
(
path
,
fromDataStream
(
dataStream
,
fields
));
...
...
dinky-client/dinky-client-1.15/src/main/java/org/dinky/executor/CustomTableEnvironmentImpl.java
View file @
578126ce
...
...
@@ -59,8 +59,11 @@ 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.operations.SinkModifyOperation
;
import
org.apache.flink.table.operations.command.ResetOperation
;
import
org.apache.flink.table.operations.command.SetOperation
;
import
org.apache.flink.table.operations.ddl.CreateTableASOperation
;
import
org.apache.flink.table.operations.ddl.CreateTableOperation
;
import
org.apache.flink.table.planner.plan.optimize.program.FlinkChainedProgram
;
import
org.apache.flink.types.Row
;
...
...
@@ -73,6 +76,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
/**
* CustomTableEnvironmentImpl
*
...
...
@@ -329,6 +334,17 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
createTemporaryView
(
s
,
fromChangelogStream
(
dataStream
));
}
@Override
public
void
executeCTAS
(
Operation
operation
)
{
if
(
operation
instanceof
CreateTableASOperation
)
{
CreateTableASOperation
createTableASOperation
=
(
CreateTableASOperation
)
operation
;
CreateTableOperation
createTableOperation
=
createTableASOperation
.
getCreateTableOperation
();
executeInternal
(
createTableOperation
);
SinkModifyOperation
sinkModifyOperation
=
createTableASOperation
.
toSinkModifyOperation
(
getCatalogManager
());
getPlanner
().
translate
(
CollUtil
.
newArrayList
(
sinkModifyOperation
));
}
}
@Override
public
<
T
>
void
createTemporaryView
(
String
path
,
DataStream
<
T
>
dataStream
,
Expression
...
fields
)
{
createTemporaryView
(
path
,
fromDataStream
(
dataStream
,
fields
));
...
...
dinky-client/dinky-client-1.16/src/main/java/org/dinky/executor/CustomTableEnvironmentImpl.java
View file @
578126ce
...
...
@@ -41,12 +41,15 @@ import org.apache.flink.table.api.ExplainDetail;
import
org.apache.flink.table.api.TableException
;
import
org.apache.flink.table.api.bridge.java.StreamTableEnvironment
;
import
org.apache.flink.table.api.internal.TableEnvironmentImpl
;
import
org.apache.flink.table.operations.CreateTableASOperation
;
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.operations.SinkModifyOperation
;
import
org.apache.flink.table.operations.command.ResetOperation
;
import
org.apache.flink.table.operations.command.SetOperation
;
import
org.apache.flink.table.operations.ddl.CreateTableOperation
;
import
org.apache.flink.table.planner.plan.optimize.program.FlinkChainedProgram
;
import
org.apache.flink.types.Row
;
...
...
@@ -64,6 +67,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
/**
* CustomTableEnvironmentImpl
*
...
...
@@ -149,7 +154,14 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
throw
new
TableException
(
"Only single statement is supported."
);
}
Operation
operation
=
operations
.
get
(
0
);
if
(
operation
instanceof
ModifyOperation
)
{
if
(
operation
instanceof
CreateTableASOperation
)
{
CreateTableASOperation
createTableAsOperation
=
(
CreateTableASOperation
)
operation
;
CreateTableOperation
createTableOperation
=
createTableAsOperation
.
getCreateTableOperation
();
executeInternal
(
createTableOperation
);
SinkModifyOperation
sinkModifyOperation
=
createTableAsOperation
.
toSinkModifyOperation
(
getCatalogManager
());
getPlanner
().
translate
(
CollUtil
.
newArrayList
(
sinkModifyOperation
));
}
else
if
(
operation
instanceof
ModifyOperation
)
{
modifyOperations
.
add
((
ModifyOperation
)
operation
);
}
else
{
throw
new
TableException
(
"Only insert statement is supported now."
);
...
...
@@ -257,4 +269,15 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
public
<
T
>
void
createTemporaryView
(
String
s
,
DataStream
<
Row
>
dataStream
,
List
<
String
>
columnNameList
)
{
createTemporaryView
(
s
,
fromChangelogStream
(
dataStream
));
}
@Override
public
void
executeCTAS
(
Operation
operation
)
{
if
(
operation
instanceof
CreateTableASOperation
)
{
CreateTableASOperation
createTableASOperation
=
(
CreateTableASOperation
)
operation
;
CreateTableOperation
createTableOperation
=
createTableASOperation
.
getCreateTableOperation
();
executeInternal
(
createTableOperation
);
SinkModifyOperation
sinkModifyOperation
=
createTableASOperation
.
toSinkModifyOperation
(
getCatalogManager
());
getPlanner
().
translate
(
CollUtil
.
newArrayList
(
sinkModifyOperation
));
}
}
}
dinky-client/dinky-client-1.17/src/main/java/org/dinky/executor/CustomTableEnvironmentImpl.java
View file @
578126ce
...
...
@@ -42,12 +42,15 @@ import org.apache.flink.table.api.ExplainFormat;
import
org.apache.flink.table.api.TableException
;
import
org.apache.flink.table.api.bridge.java.StreamTableEnvironment
;
import
org.apache.flink.table.api.internal.TableEnvironmentImpl
;
import
org.apache.flink.table.operations.CreateTableASOperation
;
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.operations.SinkModifyOperation
;
import
org.apache.flink.table.operations.command.ResetOperation
;
import
org.apache.flink.table.operations.command.SetOperation
;
import
org.apache.flink.table.operations.ddl.CreateTableOperation
;
import
org.apache.flink.table.planner.plan.optimize.program.FlinkChainedProgram
;
import
org.apache.flink.types.Row
;
...
...
@@ -65,6 +68,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
/**
* CustomTableEnvironmentImpl
*
...
...
@@ -150,7 +155,9 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
throw
new
TableException
(
"Only single statement is supported."
);
}
Operation
operation
=
operations
.
get
(
0
);
if
(
operation
instanceof
ModifyOperation
)
{
if
(
operation
instanceof
CreateTableASOperation
)
{
executeCTAS
(
operation
);
}
else
if
(
operation
instanceof
ModifyOperation
)
{
modifyOperations
.
add
((
ModifyOperation
)
operation
);
}
else
{
throw
new
TableException
(
"Only insert statement is supported now."
);
...
...
@@ -258,4 +265,15 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
public
<
T
>
void
createTemporaryView
(
String
s
,
DataStream
<
Row
>
dataStream
,
List
<
String
>
columnNameList
)
{
createTemporaryView
(
s
,
fromChangelogStream
(
dataStream
));
}
@Override
public
void
executeCTAS
(
Operation
operation
)
{
if
(
operation
instanceof
CreateTableASOperation
)
{
CreateTableASOperation
createTableASOperation
=
(
CreateTableASOperation
)
operation
;
CreateTableOperation
createTableOperation
=
createTableASOperation
.
getCreateTableOperation
();
executeInternal
(
createTableOperation
);
SinkModifyOperation
sinkModifyOperation
=
createTableASOperation
.
toSinkModifyOperation
(
getCatalogManager
());
getPlanner
().
translate
(
CollUtil
.
newArrayList
(
sinkModifyOperation
));
}
}
}
dinky-client/dinky-client-base/src/main/java/org/dinky/executor/CustomTableEnvironment.java
View file @
578126ce
...
...
@@ -32,6 +32,7 @@ import org.apache.flink.table.api.ExplainDetail;
import
org.apache.flink.table.api.bridge.java.StreamTableEnvironment
;
import
org.apache.flink.table.api.internal.TableEnvironmentInternal
;
import
org.apache.flink.table.delegation.Planner
;
import
org.apache.flink.table.operations.Operation
;
import
org.apache.flink.types.Row
;
import
java.util.Collections
;
...
...
@@ -71,4 +72,6 @@ public interface CustomTableEnvironment
}
<
T
>
void
createTemporaryView
(
String
s
,
DataStream
<
Row
>
dataStream
,
List
<
String
>
columnNameList
);
void
executeCTAS
(
Operation
operation
);
}
dinky-core/src/main/java/org/dinky/explainer/Explainer.java
View file @
578126ce
...
...
@@ -217,14 +217,41 @@ public class Explainer {
}
if
(
correct
&&
!
jobParam
.
getTrans
().
isEmpty
())
{
if
(
useStatementSet
)
{
SqlExplainResult
record
=
new
SqlExplainResult
();
List
<
String
>
inserts
=
new
ArrayList
<>();
for
(
StatementParam
item
:
jobParam
.
getTrans
())
{
if
(
item
.
getType
().
equals
(
SqlType
.
INSERT
))
{
inserts
.
add
(
item
.
getValue
());
}
else
if
(
item
.
getType
().
equals
(
SqlType
.
CTAS
))
{
SqlExplainResult
record
=
new
SqlExplainResult
();
try
{
record
.
setParseTrue
(
true
);
record
.
setExplainTrue
(
true
);
record
.
setSql
(
item
.
getValue
());
executor
.
getCustomTableEnvironment
()
.
getParser
()
.
parse
(
item
.
getValue
())
.
forEach
(
x
->
{
executor
.
getCustomTableEnvironment
().
executeCTAS
(
x
);
});
}
catch
(
Exception
e
)
{
String
error
=
LogUtil
.
getError
(
e
);
record
.
setError
(
error
);
record
.
setParseTrue
(
false
);
record
.
setExplainTrue
(
false
);
correct
=
false
;
process
.
error
(
error
);
break
;
}
finally
{
record
.
setType
(
"Modify DML"
);
record
.
setExplainTime
(
LocalDateTime
.
now
());
record
.
setIndex
(
index
);
sqlExplainRecords
.
add
(
record
);
}
}
}
if
(!
inserts
.
isEmpty
())
{
SqlExplainResult
record
=
new
SqlExplainResult
();
String
sqlSet
=
String
.
join
(
";\r\n "
,
inserts
);
try
{
record
.
setExplain
(
executor
.
explainStatementSet
(
inserts
));
...
...
dinky-core/src/main/java/org/dinky/job/JobManager.java
View file @
578126ce
...
...
@@ -350,9 +350,15 @@ public class JobManager {
}
else
if
(
useStatementSet
&&
!
useGateway
)
{
List
<
String
>
inserts
=
new
ArrayList
<>();
for
(
StatementParam
item
:
jobParam
.
getTrans
())
{
if
(
item
.
getType
().
equals
(
SqlType
.
INSERT
)
||
item
.
getType
().
equals
(
SqlType
.
CTAS
))
{
if
(
item
.
getType
().
equals
(
SqlType
.
INSERT
))
{
inserts
.
add
(
item
.
getValue
());
}
else
if
(
item
.
getType
().
equals
(
SqlType
.
CTAS
))
{
executor
.
getCustomTableEnvironment
()
.
getParser
()
.
parse
(
item
.
getValue
())
.
forEach
(
x
->
{
executor
.
getCustomTableEnvironment
().
executeCTAS
(
x
);
});
}
}
if
(!
inserts
.
isEmpty
())
{
...
...
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