use of org.apache.druid.sql.calcite.expression.builtin.RegexpExtractOperatorConversion in project druid by druid-io.
the class ExpressionsTest method testRegexpExtract.
@Test
public void testRegexpExtract() {
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("x(.)"), testHelper.makeLiteral(1)), makeExpression(SimpleExtraction.of("s", new RegexDimExtractionFn("x(.)", 1, true, null)), "regexp_extract(\"s\",'x(.)',1)"), null);
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("(o)"), testHelper.makeLiteral(1)), makeExpression(SimpleExtraction.of("s", new RegexDimExtractionFn("(o)", 1, true, null)), "regexp_extract(\"s\",'(o)',1)"), // Column "s" contains an 'o', but not at the beginning; we do match this.
"o");
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("Z"), testHelper.makeInputRef("s")), testHelper.makeLiteral("Zf(.)")), makeExpression("regexp_extract(concat('Z',\"s\"),'Zf(.)')"), "Zfo");
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("f(.)"), testHelper.makeLiteral(1)), makeExpression(SimpleExtraction.of("s", new RegexDimExtractionFn("f(.)", 1, true, null)), "regexp_extract(\"s\",'f(.)',1)"), "o");
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("f(.)")), makeExpression(SimpleExtraction.of("s", new RegexDimExtractionFn("f(.)", 0, true, null)), "regexp_extract(\"s\",'f(.)')"), "fo");
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("")), makeExpression(SimpleExtraction.of("s", new RegexDimExtractionFn("", 0, true, null)), "regexp_extract(\"s\",'')"), NullHandling.emptyToNullIfNeeded(""));
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("")), makeExpression(SimpleExtraction.of("s", new RegexDimExtractionFn("", 0, true, null)), "regexp_extract(\"s\",'')"), NullHandling.emptyToNullIfNeeded(""));
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeNullLiteral(SqlTypeName.VARCHAR), testHelper.makeLiteral("(.)")), makeExpression("regexp_extract(null,'(.)')"), null);
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeNullLiteral(SqlTypeName.VARCHAR), testHelper.makeLiteral("")), makeExpression("regexp_extract(null,'')"), null);
testHelper.testExpressionString(new RegexpExtractOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeNullLiteral(SqlTypeName.VARCHAR), testHelper.makeLiteral("null")), makeExpression("regexp_extract(null,'null')"), null);
}
Aggregations