Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into task/olm-1304-iso…
Browse files Browse the repository at this point in the history
…late-action-is-platinum-only
  • Loading branch information
paul-tavares committed Jun 16, 2021
2 parents b977353 + 8eea491 commit 5c9905f
Show file tree
Hide file tree
Showing 159 changed files with 2,119 additions and 2,014 deletions.
57 changes: 49 additions & 8 deletions docs/canvas/canvas-function-reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Alias: `condition`
[[alterColumn_fn]]
=== `alterColumn`

Converts between core types, including `string`, `number`, `null`, `boolean`, and `date`, and renames columns. See also <<mapColumn_fn>> and <<staticColumn_fn>>.
Converts between core types, including `string`, `number`, `null`, `boolean`, and `date`, and renames columns. See also <<mapColumn_fn>>, <<mathColumn_fn>>, and <<staticColumn_fn>>.

*Expression syntax*
[source,js]
Expand Down Expand Up @@ -1717,23 +1717,23 @@ Adds a column calculated as the result of other columns. Changes are made only w
|===
|Argument |Type |Description

|`id`

|`string`, `null`
|An optional id of the resulting column. When no id is provided, the id will be looked up from the existing column by the provided name argument. If no column with this name exists yet, a new column with this name and an identical id will be added to the table.

|_Unnamed_ ***

Aliases: `column`, `name`
|`string`
|The name of the resulting column.
|The name of the resulting column. Names are not required to be unique.

|`expression` ***

Aliases: `exp`, `fn`, `function`
|`boolean`, `number`, `string`, `null`
|A Canvas expression that is passed to each row as a single row `datatable`.

|`id`

|`string`, `null`
|An optional id of the resulting column. When not specified or `null` the name argument is used as id.

|`copyMetaFrom`

|`string`, `null`
Expand Down Expand Up @@ -1808,6 +1808,47 @@ Default: `"throw"`
*Returns:* `number` | `boolean` | `null`


[float]
[[mathColumn_fn]]
=== `mathColumn`

Adds a column by evaluating `TinyMath` on each row. This function is optimized for math, so it performs better than the <<mapColumn_fn>> with a <<math_fn>>.
*Accepts:* `datatable`

[cols="3*^<"]
|===
|Argument |Type |Description

|id ***
|`string`
|id of the resulting column. Must be unique.

|name ***
|`string`
|The name of the resulting column. Names are not required to be unique.

|_Unnamed_

Alias: `expression`
|`string`
|A `TinyMath` expression evaluated on each row. See https://www.elastic.co/guide/en/kibana/current/canvas-tinymath-functions.html.

|`onError`

|`string`
|In case the `TinyMath` evaluation fails or returns NaN, the return value is specified by onError. For example, `"null"`, `"zero"`, `"false"`, `"throw"`. When `"throw"`, it will throw an exception, terminating expression execution.

Default: `"throw"`

|`copyMetaFrom`

|`string`, `null`
|If set, the meta object from the specified column id is copied over to the specified target column. Throws an exception if the column doesn't exist
|===

*Returns:* `datatable`


[float]
[[metric_fn]]
=== `metric`
Expand Down Expand Up @@ -2581,7 +2622,7 @@ Default: `false`
[[staticColumn_fn]]
=== `staticColumn`

Adds a column with the same static value in every row. See also <<alterColumn_fn>> and <<mapColumn_fn>>.
Adds a column with the same static value in every row. See also <<alterColumn_fn>>, <<mapColumn_fn>>, and <<mathColumn_fn>>.

*Accepts:* `datatable`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
esKuery: {
nodeTypes: import("../common/es_query/kuery/node_types").NodeTypes;
fromKueryExpression: (expression: any, parseOptions?: Partial<import("../common").KueryParseOptions>) => import("../common").KueryNode;
toElasticsearchQuery: (node: import("../common").KueryNode, indexPattern?: import("../common").IIndexPattern | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("../../kibana_utils/common").JsonObject;
toElasticsearchQuery: (node: import("../common").KueryNode, indexPattern?: import("../common").IIndexPattern | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("@kbn/common-utils").JsonObject;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
esKuery: {
nodeTypes: import("../common/es_query/kuery/node_types").NodeTypes;
fromKueryExpression: (expression: any, parseOptions?: Partial<import("../common").KueryParseOptions>) => import("../common").KueryNode;
toElasticsearchQuery: (node: import("../common").KueryNode, indexPattern?: import("../common").IIndexPattern | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("../../kibana_utils/common").JsonObject;
toElasticsearchQuery: (node: import("../common").KueryNode, indexPattern?: import("../common").IIndexPattern | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("@kbn/common-utils").JsonObject;
}
```
2 changes: 1 addition & 1 deletion docs/user/dashboard/aggregation-reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ For information about {es} metrics aggregations, refer to {ref}/search-aggregati

| Metrics with filters
|
^| X
|
^| X
|

| Average
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"@kbn/ui-framework": "link:packages/kbn-ui-framework",
"@kbn/ui-shared-deps": "link:packages/kbn-ui-shared-deps",
"@kbn/utility-types": "link:bazel-bin/packages/kbn-utility-types",
"@kbn/common-utils": "link:bazel-bin/packages/kbn-common-utils",
"@kbn/utils": "link:bazel-bin/packages/kbn-utils",
"@loaders.gl/core": "^2.3.1",
"@loaders.gl/json": "^2.3.1",
Expand Down
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ filegroup(
"//packages/kbn-apm-utils:build",
"//packages/kbn-babel-code-parser:build",
"//packages/kbn-babel-preset:build",
"//packages/kbn-common-utils:build",
"//packages/kbn-config:build",
"//packages/kbn-config-schema:build",
"//packages/kbn-crypto:build",
Expand Down
82 changes: 82 additions & 0 deletions packages/kbn-common-utils/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")

PKG_BASE_NAME = "kbn-common-utils"
PKG_REQUIRE_NAME = "@kbn/common-utils"

SOURCE_FILES = glob(
[
"src/**/*.ts",
],
exclude = ["**/*.test.*"],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
"README.md"
]

SRC_DEPS = [
"//packages/kbn-config-schema",
"@npm//load-json-file",
"@npm//tslib",
]

TYPES_DEPS = [
"@npm//@types/jest",
"@npm//@types/node",
]

DEPS = SRC_DEPS + TYPES_DEPS

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
],
)

ts_project(
name = "tsc",
args = ['--pretty'],
srcs = SRCS,
deps = DEPS,
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = DEPS + [":tsc"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [
":%s" % PKG_BASE_NAME,
]
)

filegroup(
name = "build",
srcs = [
":npm_module",
],
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions packages/kbn-common-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/common-utils

Shared common (client and server sie) utilities shared across packages and plugins.
13 changes: 13 additions & 0 deletions packages/kbn-common-utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-common-utils'],
};
9 changes: 9 additions & 0 deletions packages/kbn-common-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kbn/common-utils",
"main": "./target/index.js",
"browser": "./target/index.js",
"types": "./target/index.d.ts",
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"private": true
}
9 changes: 9 additions & 0 deletions packages/kbn-common-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './json';
9 changes: 9 additions & 0 deletions packages/kbn-common-utils/src/json/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { JsonArray, JsonValue, JsonObject } from './typed_json';
18 changes: 18 additions & 0 deletions packages/kbn-common-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"incremental": true,
"outDir": "target",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-common-utils/src",
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}
9 changes: 6 additions & 3 deletions packages/kbn-tinymath/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
*/

const { get } = require('lodash');
const memoizeOne = require('memoize-one');
// eslint-disable-next-line import/no-unresolved
const { parse: parseFn } = require('../grammar');
const { functions: includedFunctions } = require('./functions');

module.exports = { parse, evaluate, interpret };

function parse(input, options) {
if (input == null) {
throw new Error('Missing expression');
Expand All @@ -29,9 +28,11 @@ function parse(input, options) {
}
}

const memoizedParse = memoizeOne(parse);

function evaluate(expression, scope = {}, injectedFunctions = {}) {
scope = scope || {};
return interpret(parse(expression), scope, injectedFunctions);
return interpret(memoizedParse(expression), scope, injectedFunctions);
}

function interpret(node, scope, injectedFunctions) {
Expand Down Expand Up @@ -79,3 +80,5 @@ function isOperable(args) {
return typeof arg === 'number' && !isNaN(arg);
});
}

module.exports = { parse: memoizedParse, evaluate, interpret };
2 changes: 1 addition & 1 deletion renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
packageNames: ['@elastic/charts'],
reviewers: ['markov00', 'nickofthyme'],
matchBaseBranches: ['master'],
labels: ['release_note:skip', 'v8.0.0', 'v7.14.0'],
labels: ['release_note:skip', 'v8.0.0', 'v7.14.0', 'auto-backport'],
enabled: true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/kuery/ast/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* Side Public License, v 1.
*/

import { JsonObject } from '@kbn/common-utils';
import { nodeTypes } from '../node_types/index';
import { KQLSyntaxError } from '../kuery_syntax_error';
import { KueryNode, DslQuery, KueryParseOptions } from '../types';
import { IIndexPattern } from '../../../index_patterns/types';

// @ts-ignore
import { parse as parseKuery } from './_generated_/kuery';
import { JsonObject } from '../../../../../kibana_utils/common';

const fromExpression = (
expression: string | DslQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/

import _ from 'lodash';
import { JsonObject } from '@kbn/common-utils';
import * as ast from '../ast';
import { nodeTypes } from '../node_types';
import { NamedArgTypeBuildNode } from './types';
import { JsonObject } from '../../../../../kibana_utils/common';

export function buildNode(name: string, value: any): NamedArgTypeBuildNode {
const argumentNode =
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/kuery/node_types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* WARNING: these typings are incomplete
*/

import { JsonValue } from '@kbn/common-utils';
import { IIndexPattern } from '../../../index_patterns';
import { JsonValue } from '../../../../../kibana_utils/common';
import { KueryNode } from '..';

export type FunctionName =
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { ISearchOptions as ISearchOptions_2 } from 'src/plugins/data/public';
import { ISearchSource as ISearchSource_2 } from 'src/plugins/data/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { IUiSettingsClient } from 'src/core/public';
import { JsonValue } from '@kbn/common-utils';
import { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import { Location } from 'history';
import { LocationDescriptorObject } from 'history';
Expand Down Expand Up @@ -856,7 +857,7 @@ export const esFilters: {
export const esKuery: {
nodeTypes: import("../common/es_query/kuery/node_types").NodeTypes;
fromKueryExpression: (expression: any, parseOptions?: Partial<import("../common").KueryParseOptions>) => import("../common").KueryNode;
toElasticsearchQuery: (node: import("../common").KueryNode, indexPattern?: import("../common").IIndexPattern | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("../../kibana_utils/common").JsonObject;
toElasticsearchQuery: (node: import("../common").KueryNode, indexPattern?: import("../common").IIndexPattern | undefined, config?: Record<string, any> | undefined, context?: Record<string, any> | undefined) => import("@kbn/common-utils").JsonObject;
};

// Warning: (ae-missing-release-tag) "esQuery" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down
Loading

0 comments on commit 5c9905f

Please sign in to comment.