Skip to content

Commit

Permalink
Merge pull request #2128 from scottsut/master
Browse files Browse the repository at this point in the history
Release 1.0.0-RC.2
  • Loading branch information
scottsut authored Mar 31, 2023
2 parents e19fffb + 2bd0473 commit 18deedd
Show file tree
Hide file tree
Showing 239 changed files with 6,438 additions and 3,027 deletions.
666 changes: 0 additions & 666 deletions bin/datart.sql

This file was deleted.

5 changes: 0 additions & 5 deletions bin/migrations/migration.1.0.0-alpha.3.sql

This file was deleted.

2 changes: 0 additions & 2 deletions bin/migrations/migration.1.0.0-beta.0.sql

This file was deleted.

2 changes: 0 additions & 2 deletions bin/migrations/source.1.0.0-alpha.2.sql

This file was deleted.

10 changes: 10 additions & 0 deletions config/jdbc-driver-ext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ DORIS:
adapter-class: "datart.data.provider.jdbc.adapters.DorisDataProviderAdapter"
url-prefix: "jdbc:mysql://"

STARROCKS:
db-type: "starrocks"
name: "starrocks"
driver-class: "com.mysql.cj.jdbc.Driver"
literal-quote: "'"
identifier-quote: "`"
adapter-class: "datart.data.provider.jdbc.adapters.StarRocksDataProviderAdapter"
url-prefix: "jdbc:mysql://"


6 changes: 3 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>datart-parent</artifactId>
<groupId>datart</groupId>
<version>1.0.0-rc.1</version>
<version>1.0.0-rc.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -147,7 +147,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.73</version>
<version>1.2.83</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
Expand Down Expand Up @@ -219,4 +219,4 @@
</build>


</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getDecimalPlaces() {
}

public Object parseValue(Object obj){
if (obj!=null && StringUtils.isNotBlank(this.unitKey)){
if (obj!=null && org.apache.commons.lang.math.NumberUtils.isNumber(obj.toString()) && StringUtils.isNotBlank(this.unitKey)){
UnitKey unitKey = UnitKey.getUnitKeyByValue(this.unitKey);
BigDecimal val = new BigDecimal(obj.toString()).divide(new BigDecimal(unitKey.getUnit()));
obj = val.setScale(getDecimalPlacesNum(), BigDecimal.ROUND_HALF_UP);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/datart/core/mappers/ShareMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public interface ShareMapper extends CRUDMapper {
"viz_type = #{vizType,jdbcType=VARCHAR},",
"viz_id = #{vizId,jdbcType=VARCHAR},",
"authentication_mode = #{authenticationMode,jdbcType=VARCHAR},",
"roles = #{roles,jdbcType=VARCHAR},",
"row_permission_by = #{rowPermissionBy,jdbcType=VARCHAR},",
"authentication_code = #{authenticationCode,jdbcType=VARCHAR},",
"expiry_date = #{expiryDate,jdbcType=TIMESTAMP},",
Expand All @@ -93,4 +94,4 @@ public interface ShareMapper extends CRUDMapper {
"where id = #{id,jdbcType=VARCHAR}"
})
int updateByPrimaryKey(Share record);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public interface RelWidgetElementMapperExt extends RelWidgetElementMapper {
})
List<RelWidgetElement> listWidgetElements(String widgetId);

@Select({
"<script>",
"SELECT * FROM rel_widget_element WHERE widget_id IN " +
"<foreach collection='widgetIds' item='item' index='index' open='(' close=')' separator=','> " +
" #{item} " +
"</foreach>",
"</script>"
})
List<RelWidgetElement> listWidgetElementsByIds(@Param("widgetIds") List<String> widgetId);

@Insert({
"<script>",
"INSERT INTO rel_widget_element (id, widget_id, rel_type, rel_id) VALUES " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package datart.core.mappers.ext;

import datart.core.entity.RelWidgetWidget;
import datart.core.entity.Widget;
import datart.core.mappers.RelWidgetWidgetMapper;
import org.apache.ibatis.annotations.*;

Expand Down Expand Up @@ -60,4 +59,14 @@ public interface RelWidgetWidgetMapperExt extends RelWidgetWidgetMapper {
})
List<RelWidgetWidget> listTargetWidgets(String sourceId);

@Select({
"<script>",
"SELECT rww.* " +
"FROM rel_widget_widget rww " +
"WHERE rww.source_id IN " +
"<foreach collection='sourceIds' item='item' index='index' open='(' close=')' separator=','> #{item} </foreach> ;",
"</script>",
})
List<RelWidgetWidget> listTargetWidgetsByIds(List<String> sourceIds);

}
18 changes: 18 additions & 0 deletions core/src/main/java/datart/core/mappers/ext/ScheduleMapperExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,22 @@ public interface ScheduleMapperExt extends ScheduleMapper {
})
List<Schedule> selectArchived(String orgId);

@Select({
"SELECT COUNT(*) FROM `schedule` WHERE parent_id = #{scheduleId} AND `status`!=0"
})
int checkReference(String scheduleId);

@Select({
"<script>",
"SELECT * FROM `schedule` WHERE org_id=#{orgId} AND `name` = #{name}",
"<if test=\"parentId==null\">",
" AND parent_id IS NULL ",
"</if>",
"<if test=\"parentId!=null\">",
" AND parent_id=#{parentId} ",
"</if>",
"</script>",
})
List<Schedule> checkName(String orgId, String name, String parentId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public interface SourceMapperExt extends SourceMapper {
})
Organization getOrgById(@Param("sourceId") String sourceId);

@Select({
"SELECT COUNT(*) FROM `source` WHERE parent_id = #{sourceId} AND `status`!=0"
})
int checkReference(String sourceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ public interface StoryboardMapperExt extends StoryboardMapper {
})
List<Storyboard> selectByOrg(String orgId);

@Select({
"<script>",
"SELECT * FROM storyboard WHERE org_id=#{orgId} AND `name` = #{name}",
"<if test=\"parentId==null\">",
" AND parent_id IS NULL ",
"</if>",
"<if test=\"parentId!=null\">",
" AND parent_id=#{parentId} ",
"</if>",
"</script>",
})
List<Storyboard> checkName(String orgId, String parentId, String name);

}
2 changes: 1 addition & 1 deletion data-providers/data-provider-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>datart-data-provider</artifactId>
<groupId>datart</groupId>
<version>1.0.0-rc.1</version>
<version>1.0.0-rc.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

package datart.data.provider;

import datart.core.base.processor.ExtendProcessor;
import datart.core.base.exception.Exceptions;
import datart.core.base.processor.ExtendProcessor;
import datart.core.base.processor.ProcessorResponse;
import datart.core.data.provider.*;
import datart.core.data.provider.processor.DataProviderPostProcessor;
Expand All @@ -33,7 +33,7 @@
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentHashMap;

@Service
@Slf4j
Expand All @@ -42,13 +42,30 @@ public class ProviderManager extends DataProviderExecuteOptimizer implements Dat
@Autowired(required = false)
private List<ExtendProcessor> extendProcessors = new ArrayList<ExtendProcessor>();

private static final Map<String, DataProvider> cachedDataProviders = new ConcurrentSkipListMap<>();
private static final Map<String, DataProvider> cachedDataProviders = new ConcurrentHashMap<>();

public Map<String, DataProvider> getDataProviders() {
if (cachedDataProviders.isEmpty()) {
synchronized (ProviderManager.class) {
if (cachedDataProviders.isEmpty()) {
ServiceLoader<DataProvider> load = ServiceLoader.load(DataProvider.class);
for (DataProvider dataProvider : load) {
try {
cachedDataProviders.put(dataProvider.getType(), dataProvider);
} catch (IOException e) {
log.error("", e);
}
}
}
}
}
return cachedDataProviders;
}

@Override
public List<DataProviderInfo> getSupportedDataProviders() {
ArrayList<DataProviderInfo> providerInfos = new ArrayList<>();
loadDataProviders();
for (DataProvider dataProvider : cachedDataProviders.values()) {
for (DataProvider dataProvider : getDataProviders().values()) {
try {
providerInfos.add(dataProvider.getBaseInfo());
} catch (IOException e) {
Expand Down Expand Up @@ -212,26 +229,13 @@ private void excludeColumns(Dataframe data, Set<SelectColumn> include) {


private DataProvider getDataProviderService(String type) {
if (cachedDataProviders.size() == 0) {
loadDataProviders();
}
DataProvider dataProvider = cachedDataProviders.get(type);
DataProvider dataProvider = getDataProviders().get(type);
if (dataProvider == null) {
Exceptions.msg("No data provider type " + type);
}
return dataProvider;
}

private void loadDataProviders() {
ServiceLoader<DataProvider> load = ServiceLoader.load(DataProvider.class);
for (DataProvider dataProvider : load) {
try {
cachedDataProviders.put(dataProvider.getType(), dataProvider);
} catch (IOException e) {
log.error("", e);
}
}
}

@Override
public Dataframe run(DataProviderSource source, QueryScript queryScript, ExecuteParam param) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
package datart.data.provider.calcite;

import datart.core.base.exception.Exceptions;
import datart.core.common.DateUtils;
import datart.core.data.provider.ScriptVariable;
import datart.core.data.provider.SingleTypedValue;
import datart.data.provider.calcite.custom.SqlSimpleStringLiteral;
import org.apache.calcite.sql.*;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.util.DateString;
import org.apache.calcite.util.TimestampString;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -132,15 +128,8 @@ public static SqlNode createSqlNode(SingleTypedValue value) {
}

private static SqlNode createDateSqlNode(String value, String format) {
if (StringUtils.isBlank(format)) {
return SqlLiteral.createTimestamp(new TimestampString(value), 0, SqlParserPos.ZERO);
} else if (DateUtils.isDateFormat(format)) {
return SqlLiteral.createDate(new DateString(value), SqlParserPos.ZERO);
} else if (DateUtils.isDateTimeFormat(format)) {
return SqlLiteral.createTimestamp(new TimestampString(value), 0, SqlParserPos.ZERO);
} else {
return new SqlSimpleStringLiteral(value);
}
// After 1.0.0-RC.1, date type parameters are treated as strings directly
return new SqlSimpleStringLiteral(value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public QueryScriptProcessResult process(QueryScript queryScript) {
selectSql = StringUtils.prependIfMissing(selectSql, " ", " ");

SqlBasicCall sqlBasicCall = new SqlBasicCall(SqlStdOperatorTable.AS
, new SqlNode[]{new SqlFragment("(" + selectSql + ")"), new SqlIdentifier(T, SqlParserPos.ZERO.withQuoting(true))}
, new SqlNode[]{new SqlFragment("(" + selectSql + ")"), new SqlIdentifier(T, SqlParserPos.ZERO)}
, SqlParserPos.ZERO);
QueryScriptProcessResult result = new QueryScriptProcessResult();
result.setFrom(sqlBasicCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
*/
package datart.data.provider.jdbc;

import datart.core.base.consts.ValueType;
import datart.core.base.consts.JavaType;
import datart.data.provider.calcite.custom.CustomSqlTypeName;
import datart.core.base.consts.ValueType;
import org.apache.calcite.sql.type.SqlTypeFamily;
import org.apache.calcite.sql.type.SqlTypeName;

Expand All @@ -28,12 +27,34 @@

public class DataTypeUtils {

public static ValueType sqlType2DataType(String sqlType) {
sqlType = sqlType.toUpperCase();
SqlTypeName sqlTypeName = SqlTypeName.get(sqlType);
// public static ValueType sqlType2DataType(String sqlType) {
// sqlType = sqlType.toUpperCase();
// SqlTypeName sqlTypeName = SqlTypeName.get(sqlType);
// SqlTypeFamily family;
// if (sqlTypeName == null) {
// family = CustomSqlTypeName.SQL_TYPE_FAMILY_MAP.getOrDefault(sqlType, CustomSqlTypeName.ANY).getFamily();
// } else {
// family = sqlTypeName.getFamily();
// }
// switch (family) {
// case NUMERIC:
// return ValueType.NUMERIC;
// case DATE:
// case TIME:
// case TIMESTAMP:
// case DATETIME:
// return ValueType.DATE;
// default:
// return ValueType.STRING;
// }
// }


public static ValueType jdbcType2DataType(int jdbcType) {
SqlTypeName sqlTypeName = SqlTypeName.getNameForJdbcType(jdbcType);
SqlTypeFamily family;
if (sqlTypeName == null) {
family = CustomSqlTypeName.SQL_TYPE_FAMILY_MAP.getOrDefault(sqlType, CustomSqlTypeName.ANY).getFamily();
family = SqlTypeFamily.getFamilyForJdbcType(jdbcType);
} else {
family = sqlTypeName.getFamily();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class ResultSetMapper {
public static List<Column> getColumns(ResultSet rs) throws SQLException {
ArrayList<Column> columns = new ArrayList<>();
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
String columnTypeName = rs.getMetaData().getColumnTypeName(i);
int columnType = rs.getMetaData().getColumnType(i);
String columnName = rs.getMetaData().getColumnLabel(i);
ValueType valueType = DataTypeUtils.sqlType2DataType(columnTypeName);
columns.add(Column.of(valueType,columnName));
ValueType valueType = DataTypeUtils.jdbcType2DataType(columnType);
columns.add(Column.of(valueType, columnName));
}
return columns;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ private static Dataframe executeInLocalDB(QueryScript queryScript, ExecuteParam

}
return execute(connection, queryScript, executeParam);
} finally {
if (!dataframes.isEmpty()) {
for (Dataframe dataframe : dataframes.getDataframes()) {
unregisterData(dataframe.getId());
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion data-providers/file-data-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>datart-data-provider</artifactId>
<groupId>datart</groupId>
<version>1.0.0-rc.1</version>
<version>1.0.0-rc.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion data-providers/http-data-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>datart-data-provider</artifactId>
<groupId>datart</groupId>
<version>1.0.0-rc.1</version>
<version>1.0.0-rc.2</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Loading

0 comments on commit 18deedd

Please sign in to comment.