Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -617,6 +617,17 @@ public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
),
SqlFunctionCategory.STRING);

public static final SqlFunction SUBSTR = new SqlFunction(
"SUBSTR",
SqlKind.OTHER_FUNCTION,
ARG0_VARCHAR_FORCE_NULLABLE,
null,
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.INTEGER),
OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.INTEGER, SqlTypeFamily.INTEGER)
),
SqlFunctionCategory.STRING);

public static final SqlFunction LEFT = new SqlFunction(
"LEFT",
SqlKind.OTHER_FUNCTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object StringCallGen {
case NOT_LIKE =>
generateNot(ctx, new LikeCallGen().generate(ctx, operands, new BooleanType()))

case SUBSTRING => generateSubString(ctx, operands)
case SUBSTR | SUBSTRING => generateSubString(ctx, operands)

case LEFT => generateLeft(ctx, operands.head, operands(1))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ class ScalarFunctionsTest extends ScalarTypesTestBase {

@Test
def testSubString(): Unit = {
Array("substring").foreach {
Array("substring", "substr").foreach {
substr =>
testSqlApi(s"$substr(f0, 2, 3)", "his")
testSqlApi(s"$substr(f0, 2, 100)", "his is a test String.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class SqlExpressionTest extends ExpressionTestBase {
testSqlApi("SUBSTRING('hello world', 2)", "ello world")
testSqlApi("SUBSTRING('hello world', 2, 3)", "ell")
testSqlApi("SUBSTRING('hello world', 2, 300)", "ello world")
testSqlApi("SUBSTR('hello world', 2, 3)", "ell")
testSqlApi("SUBSTR('hello world', 2)", "ello world")
testSqlApi("SUBSTR('hello world', 2, 300)", "ello world")
testSqlApi("SUBSTR('hello world', 0, 3)", "hel")
testSqlApi("INITCAP('hello world')", "Hello World")
testSqlApi("REGEXP_REPLACE('foobar', 'oo|ar', '')", "fb")
testSqlApi("REGEXP_EXTRACT('foothebar', 'foo(.*?)(bar)', 2)", "bar")
Expand Down