Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve implementation of parse command #458

Open
joshuali925 opened this issue Mar 3, 2022 · 0 comments
Open

Improve implementation of parse command #458

joshuali925 opened this issue Mar 3, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@joshuali925
Copy link
Member

Overview

There are few problems with the initial approach of parse command implementation from #411, it brings some limitations described in #359.

One of the root cause is that PPL cannot determine whether to use NamedExpression or ParseExpression when resolving identifiers. For example:

source=index | parse message "(?<firstChar>\w).*" | fields firstChar

In this query when resolving firstChar, PPL should refer to ParseExpression firstChar and derive it from field message.

source=index | parse message "(?<firstChar>\w).*" | stats count() by firstChar | fields count(), firstChar

In this query behavior should be the same when resolving firstChar in stats, but in fields command, firstChar should come from NamedExpression because message no longer exists.

To solve this issue, initial implementation always prioritizes to use ParseExpression instead of NamedExpression if both exists. If the raw text field of parse expression is missing, then it will read from tuple values. This brings the restrictions of not able to rewrite parsed fields and etc. Related code:

@Override
public ExprValue next() {
ExprValue inputValue = input.next();
ImmutableMap.Builder<String, ExprValue> mapBuilder = new Builder<>();
for (NamedExpression expr : projectList) {
ExprValue exprValue = expr.valueOf(inputValue.bindingTuples());
if (namedParseExpressions.stream()
.noneMatch(parsed -> parsed.getNameOrAlias().equals(expr.getNameOrAlias()))) {
mapBuilder.put(expr.getNameOrAlias(), exprValue);
}
}
// ParseExpression will always override NamedExpression when identifier conflicts
for (NamedExpression expr : namedParseExpressions) {
ExprValue value = inputValue.bindingTuples()
.resolve(((ParseExpression) expr.getDelegated()).getExpression());
if (value.isMissing()) {
// value will be missing after stats command, read from inputValue if it exists
// otherwise do nothing since it should not appear as a field
ExprValue exprValue = ExprValueUtils.getTupleValue(inputValue).get(expr.getNameOrAlias());
if (exprValue != null) {
mapBuilder.put(expr.getNameOrAlias(), exprValue);
}
} else {
ExprValue parsedValue = expr.valueOf(inputValue.bindingTuples());
mapBuilder.put(expr.getNameOrAlias(), parsedValue);
}
}
return ExprTupleValue.fromExprValueMap(mapBuilder.build());
}

Ideas for a better implementation:

  1. If OpenSearch supports creating fields at runtime, parse command can be pushed down to that.
  2. Do not convert parse command as parse expressions in analyzer, do it here instead?
    this.request = new OpenSearchQueryRequest(indexName,
    settings.getSettingValue(Settings.Key.QUERY_SIZE_LIMIT), exprValueFactory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant