Skip to content

Commit

Permalink
Fix FT failures
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Feb 2, 2024
1 parent 3c15ccc commit a8d77df
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/plugins/data/common/search/expressions/esql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { castEsToKbnFieldTypeName, ES_FIELD_TYPES, KBN_FIELD_TYPES } from '@kbn/
import { i18n } from '@kbn/i18n';
import type {
Datatable,
DatatableColumn,
DatatableColumnType,
ExpressionFunctionDefinition,
} from '@kbn/expressions-plugin/common';
Expand Down Expand Up @@ -237,23 +238,36 @@ export const getEsqlFn = ({ getStartDependencies }: EsqlFnArguments) => {
);
}),
map(({ rawResponse: body, warning }) => {
const columns =
body.columns?.map(({ name, type }) => ({
id: name,
name,
meta: { type: normalizeType(type) },
})) ?? [];
// all_columns in the response means that there is a separation between
// columns with data and empty columns
// columns contain only columns with data while all_columns everything
const hasEmptyColumns =
body.all_columns && body.all_columns?.length > body.columns.length;

const lookup = new Set(hasEmptyColumns ? body.columns.map(({ name }) => name) : []);
const allColumns =
(body.all_columns ?? body.columns)
?.map(({ name, type }) => ({
let emptyColumns: DatatableColumn[] = [];

if (hasEmptyColumns) {
const difference =
body.all_columns?.filter((col1) => {
return !body.columns.some((col2) => {
return col1.name === col2.name;
});
}) ?? [];
emptyColumns =
difference?.map(({ name, type }) => ({
id: name,
name,
meta: { type: normalizeType(type) },
isNull: hasEmptyColumns ? !lookup.has(name) : false,
}))
.sort(({ isNull }) => (isNull ? 1 : -1)) ?? [];

isNull: true,
})) ?? [];
}
const allColumns = [...columns, ...emptyColumns];
const columnNames = allColumns.map(({ name }) => name);
const rows = body.values.map((row) => zipObject(columnNames, row));

Expand Down

0 comments on commit a8d77df

Please sign in to comment.