fix(executor-task): 修复sql语句查询到null字段导致数组越界错误

This commit is contained in:
v-zhangjc9
2024-06-03 15:52:34 +08:00
parent 1f6f5c270a
commit 8aba2475be

View File

@@ -1,6 +1,7 @@
package com.lanyuanxiaoyao.service.executor.task; package com.lanyuanxiaoyao.service.executor.task;
import cn.hutool.core.collection.IterUtil; import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import de.vandermeer.asciitable.AsciiTable; import de.vandermeer.asciitable.AsciiTable;
import de.vandermeer.asciitable.CWC_LongestLine; import de.vandermeer.asciitable.CWC_LongestLine;
@@ -18,7 +19,6 @@ import org.apache.flink.util.CloseableIterator;
import org.apache.hudi.common.table.HoodieTableConfig; import org.apache.hudi.common.table.HoodieTableConfig;
import org.apache.hudi.common.table.HoodieTableMetaClient; import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.table.TableSchemaResolver; import org.apache.hudi.common.table.TableSchemaResolver;
import org.apache.hudi.configuration.FlinkOptions;
import org.apache.hudi.org.apache.avro.Schema; import org.apache.hudi.org.apache.avro.Schema;
import org.apache.hudi.util.AvroSchemaConverter; import org.apache.hudi.util.AvroSchemaConverter;
import org.apache.hudi.util.HoodiePipeline; import org.apache.hudi.util.HoodiePipeline;
@@ -89,7 +89,12 @@ public class SQLExecutor {
table.addRule(); table.addRule();
table.addRow(fields.toArray()); table.addRow(fields.toArray());
table.addRule(); table.addRule();
iterator.forEachRemaining(row -> table.addRow(fields.collect(row::getField).toArray())); iterator.forEachRemaining(row -> {
table.addRow(fields.collect(name -> {
Object field = row.getField(name);
return ObjectUtil.isNull(field) ? "null" : field;
}).toArray());
});
table.addRule(); table.addRule();
table.getRenderer().setCWC(new CWC_LongestLine()); table.getRenderer().setCWC(new CWC_LongestLine());
table.getContext().setGridTheme(TA_GridThemes.NONE); table.getContext().setGridTheme(TA_GridThemes.NONE);