Skip to content

Commit

Permalink
[fix][common] Fix the bug that the schema name contains middleLine (#…
Browse files Browse the repository at this point in the history
…1536)

Co-authored-by: ‘zhu-mingye’ <‘[email protected]’>
  • Loading branch information
Zzm0809 and ‘zhu-mingye’ authored Jan 11, 2023
1 parent 991811a commit 9b1a97c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
16 changes: 11 additions & 5 deletions dlink-common/src/main/java/com/dlink/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@

import com.dlink.assertion.Asserts;
import com.dlink.utils.SqlUtil;
import lombok.Getter;
import lombok.Setter;

import java.beans.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import lombok.Getter;
import lombok.Setter;



/**
Expand Down Expand Up @@ -78,12 +77,12 @@ public Table(String name, String schema, List<Column> columns) {

@Transient
public String getSchemaTableName() {
return Asserts.isNullString(schema) ? name : schema + "." + name;
return Asserts.isNullString(replaceSchemaMiddleLine(schema)) ? name : replaceSchemaMiddleLine(schema) + "." + name;
}

@Transient
public String getSchemaTableNameWithUnderline() {
return Asserts.isNullString(schema) ? name : schema + "_" + name;
return Asserts.isNullString(replaceSchemaMiddleLine(schema)) ? name : replaceSchemaMiddleLine(schema) + "_" + name;
}

@Override
Expand Down Expand Up @@ -273,4 +272,11 @@ public Object clone() {
}
return table;
}

private String replaceSchemaMiddleLine(String schema) {
if (schema.contains("-")){
return schema.replaceAll("-","_");
}
return schema;
}
}
45 changes: 21 additions & 24 deletions dlink-function/src/main/java/com/dlink/function/util/UDFUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@

package com.dlink.function.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ClassLoaderUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.engine.freemarker.FreemarkerEngine;
import com.dlink.assertion.Asserts;
import com.dlink.config.Dialect;
import com.dlink.context.DinkyClassLoaderContextHolder;
Expand All @@ -33,9 +46,12 @@
import com.dlink.pool.ClassEntity;
import com.dlink.pool.ClassPool;
import com.dlink.process.exception.DinkyException;

import groovy.lang.GroovyClassLoader;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.table.catalog.FunctionLanguage;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.nio.charset.Charset;
Expand All @@ -47,25 +63,6 @@
import java.util.Map;
import java.util.regex.Pattern;

import org.codehaus.groovy.control.CompilerConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ClassLoaderUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.engine.freemarker.FreemarkerEngine;
import groovy.lang.GroovyClassLoader;

/**
* UDFUtil
*
Expand Down Expand Up @@ -280,13 +277,13 @@ private static String md5sum(String filePath) {
return MD5.create().digestHex(FileUtil.file(filePath));
}

public static boolean isUdfStatement(String statement) {
return !StrUtil.isBlank(statement) && CollUtil.isNotEmpty(ReUtil.findAll(FUNCTION_SQL_REGEX, statement, 0));
public static boolean isUdfStatement(Pattern pattern, String statement) {
return !StrUtil.isBlank(statement) && CollUtil.isNotEmpty(ReUtil.findAll(pattern, statement, 0));
}

public static UDF toUDF(String statement) {
if (isUdfStatement(statement)) {
Pattern pattern = Pattern.compile(FUNCTION_SQL_REGEX, Pattern.CASE_INSENSITIVE);
Pattern pattern = Pattern.compile(FUNCTION_SQL_REGEX, Pattern.CASE_INSENSITIVE);
if (isUdfStatement(pattern, statement)) {
List<String> groups = CollUtil.removeEmpty(ReUtil.getAllGroups(pattern, statement));
String udfName = groups.get(1);
String className = groups.get(2);
Expand Down

0 comments on commit 9b1a97c

Please sign in to comment.