Search in sources :

Example 41 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn 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);
}
Also used : RegexpExtractOperatorConversion(org.apache.druid.sql.calcite.expression.builtin.RegexpExtractOperatorConversion) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Aggregations

RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)41 Test (org.junit.Test)40 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)15 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)13 Result (org.apache.druid.query.Result)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)5 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)5 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 SearchQuerySpec (org.apache.druid.query.search.SearchQuerySpec)3 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2 RegexFilteredDimensionSpec (org.apache.druid.query.dimension.RegexFilteredDimensionSpec)2 CascadeExtractionFn (org.apache.druid.query.extraction.CascadeExtractionFn)2 DimExtractionFn (org.apache.druid.query.extraction.DimExtractionFn)2 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)2 SearchQuerySpecDimExtractionFn (org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn)2 StringFormatExtractionFn (org.apache.druid.query.extraction.StringFormatExtractionFn)2 StrlenExtractionFn (org.apache.druid.query.extraction.StrlenExtractionFn)2 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)2