Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

[PPL] Implemeted full functionality of commands in phase0 #440

Merged
merged 45 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8a44cfc
m
chloe-zh Apr 6, 2020
204bb81
Merge branch 'feature/ppl' of github.com:opendistro-for-elasticsearch…
chloe-zh Apr 9, 2020
3bfdb28
Added antlr files
chloe-zh Apr 9, 2020
c2f63c0
Merge remote-tracking branch 'upstream/feature/ppl' into ppl-parser
chloe-zh Apr 10, 2020
084f380
Added wildcard
chloe-zh Apr 12, 2020
8c45b24
Implemented parser for commands of simple syntax
chloe-zh Apr 14, 2020
6b542eb
addressed comments
chloe-zh Apr 14, 2020
46bb1dc
Enabled parsing nested fields and arrays in field
chloe-zh Apr 16, 2020
80b0629
Added unit tests for nested fields
chloe-zh Apr 17, 2020
ddf9c5a
Added Java doc for classes
chloe-zh Apr 17, 2020
17a8503
Replaced the imported parser with static methods in the parser
chloe-zh Apr 17, 2020
784df88
Addressed comments
chloe-zh Apr 17, 2020
c251f03
Addressed comments
chloe-zh Apr 17, 2020
3a92f11
Addressed comments
chloe-zh Apr 18, 2020
412f6f0
changed LogicalPlan to UnresolvedPlan; added test for index name with…
chloe-zh Apr 20, 2020
5430902
Merge branch 'feature/ppl' of github.com:opendistro-for-elasticsearch…
chloe-zh Apr 20, 2020
ceced2d
Enabled the rest of comparison operations; modified related tests
chloe-zh Apr 20, 2020
3ae1480
Added optional arguments in commands
chloe-zh Apr 21, 2020
bd56129
Reverted nest
chloe-zh Apr 21, 2020
9489e41
Removed constant and replaced it with literalValue in antlr parser
chloe-zh Apr 21, 2020
a898546
Simplified the accept methods
chloe-zh Apr 22, 2020
daf4767
Update
chloe-zh Apr 22, 2020
384eec6
Merge branch 'ppl-parser' into parser
chloe-zh Apr 22, 2020
acb1575
Added builder pattern
chloe-zh Apr 23, 2020
2cc689b
Rolled back to remove builder
chloe-zh Apr 23, 2020
42609bc
update
chloe-zh Apr 23, 2020
092adbf
Revert "Added builder pattern"
chloe-zh Apr 23, 2020
e8c2eff
update
chloe-zh Apr 23, 2020
0c78efa
Merge remote-tracking branch 'upstream/feature/ppl' into ppl-parser
chloe-zh Apr 23, 2020
bdddc2c
Merge remote-tracking branch 'upstream/feature/ppl' into parser
chloe-zh Apr 23, 2020
09db3e5
fac
chloe-zh Apr 23, 2020
370c83d
resolved conflicts & merged d4147a981ea0ef364c247fd4da92487dfe629ea1
chloe-zh Apr 24, 2020
5698a1b
Added argument factory; refracted in tests
chloe-zh Apr 24, 2020
d309aac
Added sparkline aggregation
chloe-zh Apr 27, 2020
bfbb3f9
update
chloe-zh Apr 27, 2020
08ae59f
improved parser and argument factory test coverage
chloe-zh Apr 28, 2020
2c3df82
improved parser and argument factory test coverage
chloe-zh Apr 28, 2020
4241f5f
Added java doc for ArgumentFactory class
chloe-zh Apr 28, 2020
de40c88
Added field with optional arguments; added tests
chloe-zh Apr 29, 2020
11ebadb
Added qualifiedname node as nested field
chloe-zh Apr 29, 2020
f3a097b
Expression -> UnresolvedExpression; DSL -> AstDSL
chloe-zh May 2, 2020
72583c6
Updated copyright 2019 -> 2020
chloe-zh May 2, 2020
c3c1445
Replaced getMethod in Relation with string return type
chloe-zh May 3, 2020
d2c13ca
Addressed comments
chloe-zh May 4, 2020
d9ddd4c
Added assert in ppl service test
chloe-zh May 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@

import com.amazon.opendistroforelasticsearch.sql.ast.expression.AggregateFunction;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.And;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Argument;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.AttributeList;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Compare;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.EqualTo;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Field;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Function;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.In;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Literal;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Map;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Not;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Or;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.QualifiedName;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.UnresolvedAttribute;
import com.amazon.opendistroforelasticsearch.sql.ast.tree.Aggregation;
import com.amazon.opendistroforelasticsearch.sql.ast.tree.Filter;
Expand Down Expand Up @@ -119,5 +123,20 @@ public T visitIn(In node, C context) {
return visitChildren(node, context);
}

public T visitCompare(Compare node, C context) {
return visitChildren(node, context);
}

public T visitArgument(Argument node, C context) {
return visitChildren(node, context);
}

public T visitField(Field node, C context) {
return visitChildren(node, context);
}

public T visitQualifiedName(QualifiedName node, C context) {
return visitChildren(node, context);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amazon.opendistroforelasticsearch.sql.ast.dsl;

import com.amazon.opendistroforelasticsearch.sql.ast.expression.AggregateFunction;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.And;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Argument;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Compare;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.DataType;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.EqualTo;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.UnresolvedExpression;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Field;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Function;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.In;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Literal;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Map;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Not;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.Or;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.QualifiedName;
import com.amazon.opendistroforelasticsearch.sql.ast.expression.UnresolvedAttribute;
import com.amazon.opendistroforelasticsearch.sql.ast.tree.Aggregation;
import com.amazon.opendistroforelasticsearch.sql.ast.tree.Filter;
import com.amazon.opendistroforelasticsearch.sql.ast.tree.UnresolvedPlan;
import com.amazon.opendistroforelasticsearch.sql.ast.tree.Project;
import com.amazon.opendistroforelasticsearch.sql.ast.tree.Relation;
import java.util.Arrays;
import java.util.List;

/**
* Class of static methods to create specific node instances
*/
public class AstDSL {

public static UnresolvedPlan filter(UnresolvedPlan input, UnresolvedExpression expression) {
return new Filter(expression).attach(input);
}

public static UnresolvedPlan relation(String tableName) {
return new Relation(qualifiedName(tableName));
}

public static UnresolvedPlan project(UnresolvedPlan input, UnresolvedExpression... projectList) {
return new Project(Arrays.asList(projectList)).attach(input);
}

public static UnresolvedPlan projectWithArg(UnresolvedPlan input, List<UnresolvedExpression> argList, UnresolvedExpression... projectList) {
return new Project(Arrays.asList(projectList), argList).attach(input);
}

public static UnresolvedPlan agg(UnresolvedPlan input, List<UnresolvedExpression> aggList, List<UnresolvedExpression> sortList,
List<UnresolvedExpression> groupList, List<UnresolvedExpression> argList) {
return new Aggregation(aggList, sortList, groupList, argList).attach(input);
}

public static UnresolvedExpression qualifiedName(String... parts) {
return new QualifiedName(Arrays.asList(parts));
}

public static UnresolvedExpression equalTo(UnresolvedExpression left, UnresolvedExpression right) {
return new EqualTo(left, right);
}

public static UnresolvedExpression unresolvedAttr(String attr) {
return new UnresolvedAttribute(attr);
}

private static UnresolvedExpression literal(Object value, DataType type) {
return new Literal(value, type);
}

public static UnresolvedExpression intLiteral(Integer value) {
return literal(value, DataType.INTEGER);
}

public static UnresolvedExpression doubleLiteral(Double value) {
return literal(value, DataType.DOUBLE);
}

public static UnresolvedExpression stringLiteral(String value) {
return literal(value, DataType.STRING);
}

public static UnresolvedExpression booleanLiteral(Boolean value) {
return literal(value, DataType.BOOLEAN);
}

public static UnresolvedExpression nullLiteral() {
return literal(null, DataType.NULL);
}

public static UnresolvedExpression map(String origin, String target) {
return new Map(new Field(origin), new Field(target));
}

public static UnresolvedExpression map(UnresolvedExpression origin, UnresolvedExpression target) {
return new Map(origin, target);
}

public static UnresolvedExpression aggregate(String func, UnresolvedExpression field) {
return new AggregateFunction(func, field);
}

public static UnresolvedExpression aggregate(String func, UnresolvedExpression field, UnresolvedExpression... args) {
return new AggregateFunction(func, field, Arrays.asList(args));
}

public static UnresolvedExpression function(String funcName, UnresolvedExpression... funcArgs) {
return new Function(funcName, Arrays.asList(funcArgs));
}

public static UnresolvedExpression not(UnresolvedExpression expression) {
return new Not(expression);
}

public static UnresolvedExpression or(UnresolvedExpression left, UnresolvedExpression right) {
return new Or(left, right);
}

public static UnresolvedExpression and(UnresolvedExpression left, UnresolvedExpression right) {
return new And(left, right);
}

public static UnresolvedExpression in(UnresolvedExpression field, UnresolvedExpression... valueList) {
return new In(field, Arrays.asList(valueList));
}

public static UnresolvedExpression compare(String operator, UnresolvedExpression left, UnresolvedExpression right) {
return new Compare(operator, left, right);
}

public static UnresolvedExpression argument(String argName, UnresolvedExpression argValue) {
return new Argument(argName, argValue);
}

public static UnresolvedExpression field(UnresolvedExpression field) {
return new Field((QualifiedName) field);
}

public static UnresolvedExpression field(String field) {
return new Field(field);
}

public static UnresolvedExpression field(UnresolvedExpression field, UnresolvedExpression... fieldArgs) {
return new Field((QualifiedName) field, Arrays.asList(fieldArgs));
}

public static UnresolvedExpression field(String field, UnresolvedExpression... fieldArgs) {
return new Field(field, Arrays.asList(fieldArgs));
}

public static UnresolvedExpression field(UnresolvedExpression field, List<UnresolvedExpression> fieldArgs) {
return new Field((QualifiedName) field, fieldArgs);
}

public static UnresolvedExpression field(String field, List<UnresolvedExpression> fieldArgs) {
return new Field(field, fieldArgs);
}

public static List<UnresolvedExpression> exprList(UnresolvedExpression... exprList) {
return Arrays.asList(exprList);
}

public static List<UnresolvedExpression> defaultFieldsArgs() {
return exprList(
argument("exclude", booleanLiteral(false))
);
}

public static List<UnresolvedExpression> defaultStatsArgs() {
return exprList(
argument("partitions", intLiteral(1)),
argument("allnum", booleanLiteral(false)),
argument("delim", stringLiteral(" ")),
argument("dedupsplit", booleanLiteral(false))
);
}

public static List<UnresolvedExpression> defaultDedupArgs() {
return exprList(
argument("number", intLiteral(1)),
argument("keepevents", booleanLiteral(false)),
argument("keepempty", booleanLiteral(false)),
argument("consecutive", booleanLiteral(false))
);
}

public static List<UnresolvedExpression> defaultSortArgs() {
return exprList(
argument("count", intLiteral(1000)),
argument("desc", booleanLiteral(false))
);
}

public static List<UnresolvedExpression> defaultSortFieldArgs() {
return exprList(
argument("exclude", booleanLiteral(false)),
argument("type", nullLiteral())
);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
@ToString
@EqualsAndHashCode(callSuper = false)
@RequiredArgsConstructor
public class AggregateFunction extends Expression {
public class AggregateFunction extends UnresolvedExpression {
private final String funcName;
private final Expression field;
private final UnresolvedExpression field;
private final List<UnresolvedExpression> argList;

public AggregateFunction(String funcName, UnresolvedExpression field) {
this.funcName = funcName;
this.field = field;
this.argList = null;
chloe-zh marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public List<Expression> getChild() {
public List<UnresolvedExpression> getChild() {
return Arrays.asList(field);
}

Expand Down
Loading