-
Notifications
You must be signed in to change notification settings - Fork 25k
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
SQL: Add support for single parameter text manipulating functions #31874
Merged
astefan
merged 11 commits into
elastic:master
from
astefan:31604_unary_string_functions
Jul 12, 2018
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
20e1cfd
SQL: Add ASCII and CAST string functions
costin ec111cf
wip
costin dadbe06
Added support for several string manipulation functions. Without Pain…
astefan 57ef262
SQL: Add ASCII and CAST string functions
costin cb81677
Added Painless scripting functionality to the unary string functions.
astefan 43d94e5
Added unary text manipulating functions.
astefan b14e469
Added IT tests for unary string functions
astefan 77ff6dd
Merge branch '31604_unary_string_functions' of https://github.com/ast…
astefan 19d68c2
Renamed string functions integration testing CSV file.
astefan f295e45
Handle differently Char and Space functions, since they receive as pa…
astefan 7acd31e
Merge remote-tracking branch 'remotes/master/master' into 31604_unary…
astefan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/string/Ascii.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression.function.scalar.string; | ||
|
||
import org.elasticsearch.xpack.sql.expression.Expression; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation; | ||
import org.elasticsearch.xpack.sql.tree.Location; | ||
import org.elasticsearch.xpack.sql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.sql.type.DataType; | ||
|
||
/** | ||
* Returns the ASCII code of the leftmost character of the given (char) expression. | ||
*/ | ||
public class Ascii extends UnaryStringFunction { | ||
|
||
public Ascii(Location location, Expression field) { | ||
super(location, field); | ||
} | ||
|
||
@Override | ||
protected NodeInfo<Ascii> info() { | ||
return NodeInfo.create(this, Ascii::new, field()); | ||
} | ||
|
||
@Override | ||
protected Ascii replaceChild(Expression newChild) { | ||
return new Ascii(location(), newChild); | ||
} | ||
|
||
@Override | ||
protected StringOperation operation() { | ||
return StringOperation.ASCII; | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return DataType.INTEGER; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...rc/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/string/BitLength.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression.function.scalar.string; | ||
|
||
import org.elasticsearch.xpack.sql.expression.Expression; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation; | ||
import org.elasticsearch.xpack.sql.tree.Location; | ||
import org.elasticsearch.xpack.sql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.sql.type.DataType; | ||
|
||
/** | ||
* Returns returns the number of bits contained within the value expression. | ||
*/ | ||
public class BitLength extends UnaryStringFunction { | ||
|
||
public BitLength(Location location, Expression field) { | ||
super(location, field); | ||
} | ||
|
||
@Override | ||
protected NodeInfo<BitLength> info() { | ||
return NodeInfo.create(this, BitLength::new, field()); | ||
} | ||
|
||
@Override | ||
protected BitLength replaceChild(Expression newChild) { | ||
return new BitLength(location(), newChild); | ||
} | ||
|
||
@Override | ||
protected StringOperation operation() { | ||
return StringOperation.BIT_LENGTH; | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
//TODO investigate if a data type Long (BIGINT) wouldn't be more appropriate here | ||
return DataType.INTEGER; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/string/Char.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression.function.scalar.string; | ||
|
||
import org.elasticsearch.xpack.sql.expression.Expression; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation; | ||
import org.elasticsearch.xpack.sql.tree.Location; | ||
import org.elasticsearch.xpack.sql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.sql.type.DataType; | ||
|
||
/** | ||
* Converts an int ASCII code to a character value. | ||
*/ | ||
public class Char extends UnaryStringIntFunction { | ||
|
||
public Char(Location location, Expression field) { | ||
super(location, field); | ||
} | ||
|
||
@Override | ||
protected NodeInfo<Char> info() { | ||
return NodeInfo.create(this, Char::new, field()); | ||
} | ||
|
||
@Override | ||
protected Char replaceChild(Expression newChild) { | ||
return new Char(location(), newChild); | ||
} | ||
|
||
@Override | ||
protected StringOperation operation() { | ||
return StringOperation.CHAR; | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return DataType.KEYWORD; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...c/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/string/CharLength.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression.function.scalar.string; | ||
|
||
import org.elasticsearch.xpack.sql.expression.Expression; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation; | ||
import org.elasticsearch.xpack.sql.tree.Location; | ||
import org.elasticsearch.xpack.sql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.sql.type.DataType; | ||
|
||
/** | ||
* Returns the length (in characters) of the string expression. | ||
*/ | ||
public class CharLength extends UnaryStringFunction { | ||
|
||
public CharLength(Location location, Expression field) { | ||
super(location, field); | ||
} | ||
|
||
@Override | ||
protected NodeInfo<CharLength> info() { | ||
return NodeInfo.create(this, CharLength::new, field()); | ||
} | ||
|
||
@Override | ||
protected CharLength replaceChild(Expression newChild) { | ||
return new CharLength(location(), newChild); | ||
} | ||
|
||
@Override | ||
protected StringOperation operation() { | ||
return StringOperation.CHAR_LENGTH; | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return DataType.INTEGER; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/string/LCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression.function.scalar.string; | ||
|
||
import org.elasticsearch.xpack.sql.expression.Expression; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation; | ||
import org.elasticsearch.xpack.sql.tree.Location; | ||
import org.elasticsearch.xpack.sql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.sql.type.DataType; | ||
|
||
/** | ||
* Lowercases all uppercase letters in a string. | ||
*/ | ||
public class LCase extends UnaryStringFunction { | ||
|
||
public LCase(Location location, Expression field) { | ||
super(location, field); | ||
} | ||
|
||
@Override | ||
protected NodeInfo<LCase> info() { | ||
return NodeInfo.create(this, LCase::new, field()); | ||
} | ||
|
||
@Override | ||
protected LCase replaceChild(Expression newChild) { | ||
return new LCase(location(), newChild); | ||
} | ||
|
||
@Override | ||
protected StringOperation operation() { | ||
return StringOperation.LCASE; | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return DataType.KEYWORD; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/string/LTrim.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression.function.scalar.string; | ||
|
||
import org.elasticsearch.xpack.sql.expression.Expression; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation; | ||
import org.elasticsearch.xpack.sql.tree.Location; | ||
import org.elasticsearch.xpack.sql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.sql.type.DataType; | ||
|
||
/** | ||
* Trims the leading whitespaces. | ||
*/ | ||
public class LTrim extends UnaryStringFunction { | ||
|
||
public LTrim(Location location, Expression field) { | ||
super(location, field); | ||
} | ||
|
||
@Override | ||
protected NodeInfo<LTrim> info() { | ||
return NodeInfo.create(this, LTrim::new, field()); | ||
} | ||
|
||
@Override | ||
protected LTrim replaceChild(Expression newChild) { | ||
return new LTrim(location(), newChild); | ||
} | ||
|
||
@Override | ||
protected StringOperation operation() { | ||
return StringOperation.LTRIM; | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return DataType.KEYWORD; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...l/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/string/Length.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression.function.scalar.string; | ||
|
||
import org.elasticsearch.xpack.sql.expression.Expression; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation; | ||
import org.elasticsearch.xpack.sql.tree.Location; | ||
import org.elasticsearch.xpack.sql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.sql.type.DataType; | ||
|
||
/** | ||
* Returns the length (number of characters) in a string, excluding the trailing blanks. | ||
*/ | ||
public class Length extends UnaryStringFunction { | ||
|
||
public Length(Location location, Expression field) { | ||
super(location, field); | ||
} | ||
|
||
@Override | ||
protected NodeInfo<Length> info() { | ||
return NodeInfo.create(this, Length::new, field()); | ||
} | ||
|
||
@Override | ||
protected Length replaceChild(Expression newChild) { | ||
return new Length(location(), newChild); | ||
} | ||
|
||
@Override | ||
protected StringOperation operation() { | ||
return StringOperation.LENGTH; | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return DataType.INTEGER; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PostgreSQL returns an
int
so we're probably safe doing it. They aren't always right, but they usually are.