Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Aug 16, 2022
1 parent 5fbc10b commit e4f786e
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,32 @@ export interface DataVisualizerGridEmbeddableInput extends EmbeddableInput {
query?: Query | AggregateQuery;
visibleFieldNames?: string[];
filters?: Filter[];
/**
* Whether to show the mini chart distributions when table is first rendered
*/
showPreviewByDefault?: boolean;
/**
* Whether to show option directly in table rows to edit the fields in the data view
*/
allowEditDataView?: boolean;
/**
* Callback to add a filter to filter bar
*/
onAddFilter?: (field: DataViewField | string, value: string, type: '+' | '-') => void;
/**
* Session ID used for Kibana's search to save and restore search sessions
*/
sessionId?: string;
/**
* List of fields to fetch field statistics for
* since we might not have fetch all fields at once, but rather all that are available
*/
fieldsToFetch?: string[];
/**
* The preferred mode for sampling data for the field statistics
* default as 'autoRandomSampler'
*/
samplingMode?: string;
}
export interface DataVisualizerGridEmbeddableOutput extends EmbeddableOutput {
showDistributions?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,41 @@ export interface DataVisualizerGridInput {
dataView: DataView;
savedSearch?: SavedSearch | SavedSearchSavedObject | null;
query?: Query;
/**
* List of fields/rows to show in the table (e.g. Discover's 'Selected fields')
*/
visibleFieldNames?: string[];
filters?: Filter[];
/**
* Whether to show the mini chart distributions when table is first rendered
*/
showPreviewByDefault?: boolean;
/**
* Whether to show option directly in table rows to edit the fields in the data view
*/
allowEditDataView?: boolean;
/**
* Unique embeddable id as there might be multiple instances in Dashboard
*/
id?: string;
/**
* Callback to add a filter to filter bar
*/
onAddFilter?: (field: DataViewField | string, value: string, type: '+' | '-') => void;
/**
* Session ID used for Kibana's search to save and restore search sessions
*/
sessionId?: string;
/**
* List of fields to fetch field statistics for
* since we might not have fetch all fields at once, but rather all that are available
*/
fieldsToFetch?: string[];
/**
* The preferred mode for sampling data for the field statistics
* default as 'autoRandomSampler'
*/
samplingMode?: string;
}
export type DataVisualizerGridEmbeddableInput = EmbeddableInput & DataVisualizerGridInput;
export type DataVisualizerGridEmbeddableOutput = EmbeddableOutput;
Expand Down Expand Up @@ -82,8 +106,15 @@ export const EmbeddableWrapper = ({
[dataVisualizerListState, onOutputChange]
);

const { configs, searchQueryLanguage, searchString, extendedColumns, progress, setLastRefresh } =
useDataVisualizerGridData(input, dataVisualizerListState);
const {
configs,
searchQueryLanguage,
searchString,
extendedColumns,
progress,
setLastRefresh,
overallStats,
} = useDataVisualizerGridData(input, dataVisualizerListState);

useEffect(() => {
setLastRefresh(Date.now());
Expand Down Expand Up @@ -141,6 +172,7 @@ export const EmbeddableWrapper = ({
showPreviewByDefault={input?.showPreviewByDefault}
onChange={onOutputChange}
loading={progress < 100}
totalCount={overallStats?.documentCountStats?.totalCount ?? 0}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export function useFieldStatsSearchStrategy(
sessionId: searchStrategyParams?.sessionId,
};

console.log('samplingProbability', samplingProbability);
const batches = createBatchedRequests(
pageOfConfigs.map((config, idx) => ({
fieldName: config.fieldName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,7 @@ export function useOverallStats<TParams extends OverallStatsSearchStrategyParams

const sub = rateLimitingForkJoin<
AggregatableFieldOverallStats | NonAggregatableFieldOverallStats | undefined
>(
[
// from(
// getDocumentCountStats(
// data.search,
// searchStrategyParams,
// searchOptions,
// browserSessionSeed,
// probability
// )
// ),
...aggregatableOverallStatsObs,
...nonAggregatableFieldsObs,
],
MAX_CONCURRENT_REQUESTS
);
>([...aggregatableOverallStatsObs, ...nonAggregatableFieldsObs], MAX_CONCURRENT_REQUESTS);

searchSubscription$.current = sub.subscribe({
next: (value) => {
Expand All @@ -245,7 +230,6 @@ export function useOverallStats<TParams extends OverallStatsSearchStrategyParams
});

const totalCount = documentCountStats?.totalCount ?? 0;
console.log('aggregatableOverallStatsResp', aggregatableOverallStatsResp);

const aggregatableOverallStats = processAggregatableFieldsExistResponse(
aggregatableOverallStatsResp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getDateFieldsStatsRequest = (
params: FieldStatsCommonRequestParams,
fields: Field[]
) => {
const { index, query, runtimeFieldMap, samplerShardSize } = params;
const { index, query, runtimeFieldMap } = params;

const size = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ export const getDocumentCountStats = async (
index,
body: {
query,
aggs: aggregations,
...(Array.isArray(fieldsToFetch) &&
timeFieldName !== undefined &&
intervalMs !== undefined &&
intervalMs > 0
? { aggs: aggregations }
: {}),
...(isPopulatedObject(runtimeFieldMap) ? { runtime_mappings: runtimeFieldMap } : {}),
},
track_total_hits: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ISearchOptions,
} from '@kbn/data-plugin/common';
import type { ISearchStart } from '@kbn/data-plugin/public';
import { buildSamplerAggregation, getSamplerAggregationsResponsePath } from '@kbn/ml-agg-utils';
import { getSamplerAggregationsResponsePath } from '@kbn/ml-agg-utils';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import { buildRandomSamplerAggregation } from './build_random_sampler_agg';
import { MAX_PERCENT, PERCENTILE_SPACING, SAMPLER_TOP_TERMS_THRESHOLD } from './constants';
Expand All @@ -35,7 +35,7 @@ export const getNumericFieldsStatsRequest = (
params: FieldStatsCommonRequestParams,
fields: Field[]
) => {
const { index, query, runtimeFieldMap, samplerShardSize } = params;
const { index, query, runtimeFieldMap } = params;

const size = 0;

Expand Down Expand Up @@ -79,14 +79,13 @@ export const getNumericFieldsStatsRequest = (
} as AggregationsTermsAggregation,
};

// If cardinality >= SAMPLE_TOP_TERMS_THRESHOLD, run the top terms aggregation
// in a sampler aggregation, even if no sampling has been specified (samplerShardSize < 1).
if (samplerShardSize < 1 && field.cardinality >= SAMPLER_TOP_TERMS_THRESHOLD) {
aggs[`${safeFieldName}_top`] = buildSamplerAggregation(
if (field.cardinality >= SAMPLER_TOP_TERMS_THRESHOLD) {
aggs[`${safeFieldName}_top`] = buildRandomSamplerAggregation(
{
top,
},
0.05
params.samplingProbability,
params.browserSessionSeed
);
} else {
aggs[`${safeFieldName}_top`] = top;
Expand Down Expand Up @@ -132,7 +131,6 @@ export const fetchNumericFieldsStats = (
if (!isIKibanaSearchResponse(resp)) return resp;

const aggregations = resp.rawResponse.aggregations;
console.log('NUMERIC aggregations', aggregations);
const aggsPath = getSamplerAggregationsResponsePath(samplerShardSize);

const batchStats: NumericFieldStats[] = [];
Expand All @@ -151,7 +149,7 @@ export const fetchNumericFieldsStats = (
);

const topAggsPath = [...aggsPath, `${safeFieldName}_top`];
if (samplerShardSize < 1 && field.cardinality >= SAMPLER_TOP_TERMS_THRESHOLD) {
if (field.cardinality >= SAMPLER_TOP_TERMS_THRESHOLD) {
topAggsPath.push('top');
}

Expand All @@ -163,8 +161,7 @@ export const fetchNumericFieldsStats = (
min: get(fieldStatsResp, 'min', 0),
max: get(fieldStatsResp, 'max', 0),
avg: get(fieldStatsResp, 'avg', 0),
isTopValuesSampled:
field.cardinality >= SAMPLER_TOP_TERMS_THRESHOLD || samplerShardSize > 0,
isTopValuesSampled: field.cardinality >= SAMPLER_TOP_TERMS_THRESHOLD,
topValues,
topValuesSampleSize: get(aggregations, ['sample', 'doc_count']),
// @todo: remove
Expand All @@ -188,7 +185,6 @@ export const fetchNumericFieldsStats = (
);
}

console.log(stats.fieldName, stats);
batchStats.push(stats);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getStringFieldStatsRequest = (
params: FieldStatsCommonRequestParams,
fields: Field[]
) => {
const { index, query, runtimeFieldMap, samplerShardSize } = params;
const { index, query, runtimeFieldMap } = params;

const size = 0;

Expand All @@ -50,9 +50,7 @@ export const getStringFieldStatsRequest = (
} as AggregationsTermsAggregation,
};

// If cardinality >= SAMPLE_TOP_TERMS_THRESHOLD, run the top terms aggregation
// in a sampler aggregation, even if no sampling has been specified (samplerShardSize < 1).
if (samplerShardSize < 1 && field.cardinality >= SAMPLER_TOP_TERMS_THRESHOLD) {
if (field.cardinality >= SAMPLER_TOP_TERMS_THRESHOLD) {
aggs[`${safeFieldName}_top`] = {
sampler: {
shard_size: SAMPLER_TOP_TERMS_SHARD_SIZE,
Expand Down Expand Up @@ -107,9 +105,6 @@ export const fetchStringFieldsStats = (
const aggsPath = getSamplerAggregationsResponsePath(samplerShardSize);
const batchStats: StringFieldStats[] = [];

console.log('fields', fields);
console.log('aggregations', aggregations);

fields.forEach((field, i) => {
const safeFieldName = field.safeFieldName;

Expand All @@ -128,7 +123,6 @@ export const fetchStringFieldsStats = (
// @todo: remove
topValuesSamplerShardSize: get(aggregations, ['sample', 'doc_count']),
};
console.log(stats.fieldName, stats);

batchStats.push(stats);
});
Expand Down

0 comments on commit e4f786e

Please sign in to comment.