forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL: Add support for single parameter text manipulating functions (el…
…astic#31874) Added support for ASCII, BIT_LENGTH, CHAR, CHAR_LENGTH, LCASE, LENGTH, LTRIM, RTRIM, SPACE, UCASE functions. Wherever Painless scripting is necessary (WHERE conditions, ORDER BY etc), those scripts are being used.
- Loading branch information
Showing
31 changed files
with
1,227 additions
and
3 deletions.
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.