Skip to content

Commit

Permalink
[Fix][Metric] Some Metric plugins Support SQL server grammar.
Browse files Browse the repository at this point in the history
  • Loading branch information
zeno.zuo committed Nov 13, 2023
1 parent 0f47081 commit e78a05f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public class ConfigConstants {

public static final String STRING_TYPE = "string_type";

public static final String LEN_FUNCTION = "len_function";

public static final String IF_FUNCTION = "if_function";

public static final String LIMIT_TOP_50 = "limitTop50";

public static final String LIMIT_KEY = "limit_key";

public static final String LENGTH_KEY = "length_key";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public Map<String, String> getDialectKeyMap() {
dialectKeyMap.put(REGEX_KEY, "${column} regexp '${regexp}'");
dialectKeyMap.put(NOT_REGEX_KEY, "${column} not regexp '${regexp}'");
dialectKeyMap.put(STRING_TYPE, "varchar");
dialectKeyMap.put(LENGTH_KEY, "length(${column})");
dialectKeyMap.put(LEN_FUNCTION, "length");
dialectKeyMap.put(IF_FUNCTION, "if");
dialectKeyMap.put(LIMIT_TOP_50, " limit 50");
dialectKeyMap.put(LENGTH_KEY, "${len_function}(${column})");
return dialectKeyMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
import java.util.Map;

import static io.datavines.common.ConfigConstants.STRING_TYPE;
import static io.datavines.common.ConfigConstants.LEN_FUNCTION;
import static io.datavines.common.ConfigConstants.IF_FUNCTION;
import static io.datavines.common.ConfigConstants.LIMIT_TOP_50;

public class SqlServerDialect extends JdbcDialect {

@Override
public Map<String, String> getDialectKeyMap() {
super.getDialectKeyMap();
dialectKeyMap.put(STRING_TYPE, "char");
dialectKeyMap.put(LEN_FUNCTION, "len");
dialectKeyMap.put(IF_FUNCTION, "iif");
dialectKeyMap.put(LIMIT_TOP_50, " OFFSET 0 ROWS FETCH NEXT 50 ROWS ONLY");
return dialectKeyMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public ExecuteSql getActualValue(Map<String,String> inputParameter) {
ExecuteSql executeSql = new ExecuteSql();
executeSql.setResultTable("invalidate_count_"+uniqueKey);
StringBuilder actualValueSql = new StringBuilder();
actualValueSql.append("select concat(k, '\001', cast(count as ${string_type})) as actual_value_").append(uniqueKey).append(" from (select if(${column} is null, 'NULL', cast(${column} as ${string_type})) as k, count(1) as count from ${table}");
actualValueSql.append("select concat(k, '\001', cast(count as ${string_type})) as actual_value_").append(uniqueKey).append(" from (select ${if_function}(${column} is null, 'NULL', cast(${column} as ${string_type})) as k, count(1) as count from ${table}");
if (filters.size() > 0) {
actualValueSql.append(" where ").append(String.join(" and ", filters));
}

actualValueSql.append(" group by ${column} order by count desc limit 50) T");
actualValueSql.append(" group by ${column} order by count desc ${limitTop50}) T");
executeSql.setSql(actualValueSql.toString());
executeSql.setErrorOutput(false);
return executeSql;
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<lz4.version>1.3.0</lz4.version>
<commons-configuration.version>1.8</commons-configuration.version>
<hive.version>2.1.0</hive.version>
<sqlserver.version>6.1.0.jre8</sqlserver.version>
<hikari.version>4.0.3</hikari.version>
<spring.version>5.3.12</spring.version>
<kerberos.version>1.0.1.RELEASE</kerberos.version>
Expand Down Expand Up @@ -562,6 +563,11 @@
<version>${hive.version}</version>
</dependency>

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${sqlserver.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
Expand Down

0 comments on commit e78a05f

Please sign in to comment.