Skip to content

Commit 30a07e9

Browse files
authored
Merge pull request running-elephant#1737 from running-elephant/pre-release
Pre release - 1.0.0-rc.0
2 parents bbd4d41 + 748cb37 commit 30a07e9

File tree

256 files changed

+59624
-2663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+59624
-2663
lines changed

.github/workflows/dev-ut-stage.js.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ "dev" ]
9+
pull_request:
10+
branches: [ "dev" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
node-version: [14.x, 16.x]
20+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
cache: 'npm'
29+
cache-dependency-path: '**/package-lock.json'
30+
- run: npm ci
31+
working-directory: ./frontend
32+
- run: npm run build --if-present
33+
working-directory: ./frontend
34+
- run: npm run test:ci
35+
working-directory: ./frontend

config/jdbc-driver-ext.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#EXAPLE:
22
# db-type: "example"
33
# name: "example"
4-
# driver-class: "com.example.jdbc.Driver"
54
# literal-quote: "'"
65
# identifier-quote: "`"
7-
# url-prefix: jdbc:example://
6+
# driver-class: "com.example.jdbc.Driver" # optional
7+
# url-prefix: "jdbc:example://" # optional
8+
# sql-dialect: "datart.data.provider.calcite.dialect.ExampleSqlDialectSupport" # optional
9+
# identifier-end-quote: "`" # optional
10+
# literal-end-quote: "'" # optional
11+
# identifier-escaped-quote: "`" # optional
12+
# adapter-class: 'datart.data.provider.jdbc.adapters.ExampleDataProviderAdapter' # optional
13+
# quote-identifiers: true # optional
14+
# support-sql-limit: true # optional
15+
#
816

917
IMPALA:
1018
db-type: "impala"

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>datart-parent</artifactId>
77
<groupId>datart</groupId>
8-
<version>1.0.0-beta.4</version>
8+
<version>1.0.0-rc.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

core/src/main/java/datart/core/data/provider/Dataframe.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import lombok.Data;
2424

2525
import java.io.Serializable;
26-
import java.util.Collections;
27-
import java.util.List;
26+
import java.util.*;
27+
import java.util.stream.Collectors;
2828

2929

3030
@Data
@@ -62,4 +62,51 @@ public static Dataframe empty() {
6262
return dataframe;
6363
}
6464

65+
// 按照指定的列定义,将数据集按照表名称进行分割,以还原原始表结构
66+
public Dataframes splitByTable(Map<String, Column> newSchema) {
67+
Map<Integer, String> tableColumnIndex = new HashMap<>();
68+
for (int i = 0; i < columns.size(); i++) {
69+
Column column = columns.get(i);
70+
Column schemaColumn = newSchema.get(column.columnKey());
71+
tableColumnIndex.put(i, schemaColumn.tableName());
72+
}
73+
Map<String, List<List<Object>>> tableRows = newSchema
74+
.values()
75+
.stream()
76+
.map(Column::tableName)
77+
.distinct()
78+
.collect(Collectors.toMap(k -> k, v -> new ArrayList()));
79+
for (List<Object> row : rows) {
80+
int i = 0;
81+
Map<String, List<Object>> tableRowMap = new HashMap<>();
82+
for (Object item : row) {
83+
String tableName = tableColumnIndex.get(i);
84+
tableRowMap.computeIfAbsent(tableName, v -> new ArrayList<>()).add(item);
85+
i++;
86+
}
87+
for (String key : tableRowMap.keySet()) {
88+
tableRows.get(key).add(tableRowMap.get(key));
89+
}
90+
}
91+
Map<String, List<Column>> tableColumns = new HashMap<>();
92+
for (int i = 0; i < columns.size(); i++) {
93+
Column column = columns.get(i);
94+
Column newColumn = newSchema.get(column.columnKey());
95+
String tableName = newColumn.tableName();
96+
newColumn.setName(newColumn.columnName());
97+
tableColumns.computeIfAbsent(tableName, v -> new ArrayList<>())
98+
.add(newColumn);
99+
}
100+
Dataframe[] dataframes = tableColumns.keySet().stream()
101+
.map(tableName -> {
102+
Dataframe df = new Dataframe();
103+
df.setName(tableName);
104+
df.setColumns(tableColumns.get(tableName));
105+
df.setRows(tableRows.get(tableName));
106+
return df;
107+
}).toArray(Dataframe[]::new);
108+
return Dataframes.of(id, dataframes);
109+
}
110+
111+
65112
}

core/src/main/java/datart/core/data/provider/Dataframes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Dataframes implements Serializable {
3030

3131
private final String key;
3232

33-
List<Dataframe> dataframes;
33+
private final List<Dataframe> dataframes;
3434

3535
private Dataframes(String key) {
3636
this.key = "DB" + key;
@@ -54,4 +54,8 @@ public static Dataframes of(String key, Dataframe... dataframes) {
5454
public void add(Dataframe df) {
5555
dataframes.add(df);
5656
}
57+
58+
public int size() {
59+
return dataframes.size();
60+
}
5761
}

core/src/main/java/datart/core/mappers/ext/ShareMapperExt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public interface ShareMapperExt extends ShareMapper {
2929

3030
@Select({"<script>",
31-
"SELECT * FROM `share` where viz_id = #{vizId} ORDER BY create_time",
31+
"SELECT * FROM `share` where viz_id = #{vizId} AND create_by &lt;&gt; 'SCHEDULER' ORDER BY create_time",
3232
"</script>"})
3333
List<Share> selectByViz(String vizId);
3434

data-providers/data-provider-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>datart-data-provider</artifactId>
77
<groupId>datart</groupId>
8-
<version>1.0.0-beta.4</version>
8+
<version>1.0.0-rc.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

data-providers/data-provider-base/src/main/java/datart/data/provider/ProviderManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private void excludeColumns(Dataframe data, Set<SelectColumn> include) {
195195
if (include
196196
.stream()
197197
.noneMatch(selectColumn ->
198-
column.getName().equals(selectColumn.getColumnKey()) || column.getName().equals(selectColumn.getAlias()))) {
198+
column.columnKey().equals(selectColumn.getColumnKey()) || column.columnKey().equals(selectColumn.getAlias()))) {
199199
excludeIndex.add(i);
200200
}
201201
}

data-providers/data-provider-base/src/main/java/datart/data/provider/calcite/SqlVariableVisitor.java

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
*/
1818
package datart.data.provider.calcite;
1919

20+
import datart.core.base.exception.Exceptions;
2021
import datart.core.data.provider.ScriptVariable;
2122
import datart.data.provider.jdbc.SimpleVariablePlaceholder;
23+
import datart.data.provider.script.SqlStringUtils;
2224
import datart.data.provider.script.VariablePlaceholder;
2325
import lombok.extern.slf4j.Slf4j;
2426
import org.apache.calcite.sql.*;
@@ -121,16 +123,10 @@ private void createVariablePlaceholders(SqlCall logicExpressionCall, Set<SqlIden
121123
}
122124

123125
logicExpressionCall = SpecialSqlCallConverter.convert(logicExpressionCall);
124-
int startIndex = logicExpressionCall.getParserPosition().getColumnNum();
125-
int endIndex = logicExpressionCall.getParserPosition().getEndColumnNum();
126-
// 处理calcite不把左右括号算进index,导致的index错位问题
127-
if (startIndex > 1 && srcSql.charAt(startIndex - 2) == '(') {
128-
startIndex = startIndex - 1;
129-
}
130-
if (endIndex < srcSql.length() && srcSql.charAt(endIndex) == ')') {
131-
endIndex = endIndex + 1;
132-
}
133-
String originalSqlFragment = srcSql.substring(startIndex - 1, endIndex).trim();
126+
int startIndex = logicExpressionCall.getParserPosition().getColumnNum() - 1;
127+
int endIndex = logicExpressionCall.getParserPosition().getEndColumnNum() - 1;
128+
129+
String originalSqlFragment = fixMissedParentheses(srcSql, startIndex, endIndex);
134130

135131
List<ScriptVariable> variables = new LinkedList<>();
136132
for (SqlIdentifier identifier : variableIdentifier) {
@@ -145,4 +141,50 @@ private void createVariablePlaceholders(SqlCall logicExpressionCall, Set<SqlIden
145141
variablePlaceholders.add(new VariablePlaceholder(variables, sqlDialect, logicExpressionCall, originalSqlFragment));
146142
}
147143

144+
// 处理calcite某些情况下不把左右括号算进index,导致的index错位问题
145+
private String fixMissedParentheses(String srcSql, int startIndex, int endIndex) {
146+
147+
String originalSqlFragment = srcSql.substring(startIndex, endIndex + 1).trim();
148+
149+
char[] missedParentheses = SqlStringUtils.findMissedParentheses(originalSqlFragment);
150+
if (missedParentheses.length != 0) {
151+
int left = 0;
152+
int right = 0;
153+
for (char parenthesis : missedParentheses) {
154+
if (parenthesis == '(') {
155+
left++;
156+
} else {
157+
right++;
158+
}
159+
}
160+
while (left != 0) {
161+
startIndex--;
162+
if (startIndex < 0) {
163+
Exceptions.msg("There are mismatched parentheses nearby " + originalSqlFragment);
164+
}
165+
if (srcSql.charAt(startIndex) == ' ') {
166+
continue;
167+
}
168+
if (srcSql.charAt(startIndex) == '(') {
169+
left--;
170+
}
171+
}
172+
while (right != 0) {
173+
endIndex++;
174+
if (endIndex >= srcSql.length()) {
175+
Exceptions.msg("There are mismatched parentheses nearby " + originalSqlFragment);
176+
}
177+
if (srcSql.charAt(endIndex) == ' ') {
178+
continue;
179+
}
180+
if (srcSql.charAt(endIndex) == ')') {
181+
right--;
182+
} else {
183+
Exceptions.msg("There are mismatched parentheses nearby " + originalSqlFragment);
184+
}
185+
}
186+
}
187+
return srcSql.substring(startIndex, endIndex + 1).trim();
188+
}
189+
148190
}

data-providers/data-provider-base/src/main/java/datart/data/provider/calcite/StructScriptProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public QueryScriptProcessResult process(QueryScript queryScript) {
5252
SqlNode conditionNode = null;
5353
if (!CollectionUtils.isEmpty(tableJoin.getConditions())) {
5454
for (JoinCondition joinCondition : tableJoin.getConditions()) {
55+
if (!joinCondition.isValid()) {
56+
continue;
57+
}
5558
SqlBasicCall condition = new SqlBasicCall(SqlStdOperatorTable.EQUALS
5659
, new SqlNode[]{SqlNodeUtils.createSqlIdentifier(joinCondition.getLeft())
5760
, SqlNodeUtils.createSqlIdentifier(joinCondition.getRight())}

0 commit comments

Comments
 (0)