为了更快的定位您的问题,请提供以下信息,谢谢
【详述】问题详细描述
【背景】做过哪些操作?
【业务影响】
【StarRocks版本】例如:2.5.4
【集群规模】例如:1fe(1 follower)+1be(fe与be混部)
【机器信息】CPU虚拟核/内存/网卡,例如:48C/64G/万兆
【联系方式】为了在解决问题过程中能及时联系到您获取一些日志信息,请补充下您的联系方式,例如:社区群14-石头,谢谢
【附件】
- fe.log/beINFO/相应截图
- 慢查询:
- Profile信息
- 并行度:show variables like ‘%parallel_fragment_exec_instance_num%’;
- pipeline是否开启:show variables like ‘%pipeline%’;
- be节点cpu和内存使用率截图
- 查询报错:
- query_dump,怎么获取query_dump文件
- be crash
- be.out
udf代码如下:
package cn.hsh.udf;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hive.ql.parse.ASTNode;
import org.apache.hadoop.hive.ql.parse.ParseDriver;
import org.apache.hadoop.hive.ql.parse.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class UDFLineageGet {
private final static Logger logger = LoggerFactory.getLogger(UDFLineageGet.class);
public final String evaluate(String sql) {
if (sql == null ) return "";
try {
StringBuilder output = new StringBuilder();
boolean checkIsSql = StringUtils.containsIgnoreCase(sql, "from");
logger.info("checkIsSql status:"+checkIsSql);
if(checkIsSql){
List<String> sourceTables = parseSourceTables(sql);
logger.info("UDFLineageGet Input tables = " + sourceTables);
if( sourceTables.size() > 0){
String result = sourceTables.stream().collect(Collectors.joining(", "));
return result;
}
}
return "";
} catch (Exception e) {
return "";
}
}
public List<String> parseSourceTables(String sql) {
List<String> sourceTables = new ArrayList<>();
try {
ParseDriver pd = new ParseDriver();
ASTNode ast = pd.parse(sql);
// 遍历AST并提取来源表名
extractSourceTables(ast, sourceTables);
} catch (ParseException e) {
// 解析异常处理
e.printStackTrace();
}
return sourceTables;
}
private void extractSourceTables(ASTNode node, List<String> sourceTables) {
if (node.getToken() != null) {
String tokenText = node.getToken().getText();
if (tokenText != null && tokenText.equalsIgnoreCase("TOK_TABREF")) {
// 提取表名
ASTNode tableNode = (ASTNode) node.getChild(0);
String tableName = tableNode.getChild(0).getText();
sourceTables.add(tableName);
}
}
// 递归遍历子节点
int childCount = node.getChildCount();
for (int i = 0; i < childCount; i++) {
ASTNode child = (ASTNode) node.getChild(i);
extractSourceTables(child, sourceTables);
}
}
public static void main(String[] args) {
UDFLineageGet uDFLineageGet = new UDFLineageGet();
List<String> sqlList = new ArrayList<>();
String sql1 =" select * from aggregate_tbl limit 1 ";
String sql2 =" select stmt,udf_lineage_get(stmt) from starrocks_audit_tbl_test where isQuery=1 ";
String sql3 =" select @@version_comment limit 1";
String sql4 =" select * from starrocks_audit_tbl_test";
sqlList.add(sql1);
sqlList.add(sql2);
sqlList.add(sql3);
sqlList.add(sql4);
for(String sql: sqlList){
String res = uDFLineageGet.evaluate(sql);
System.out.println(res);
}
}
}
运行结果如下:
解析结果不正确,有串行