-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exposing optional replaceMissingValueWith in lookup function and macr…
…os (#14956) * Exposing optional replaceMissingValueWith in lookup function and macros * args range validation * Updating docs * Addressing comments * Update docs/querying/sql-scalar.md Co-authored-by: Clint Wylie <[email protected]> * Update docs/querying/sql-functions.md Co-authored-by: Clint Wylie <[email protected]> * Addressing comments --------- Co-authored-by: Clint Wylie <[email protected]>
- Loading branch information
1 parent
d038237
commit f1edd67
Showing
10 changed files
with
225 additions
and
8 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
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
95 changes: 95 additions & 0 deletions
95
processing/src/test/java/org/apache/druid/query/expression/LookupExprMacroTest.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,95 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.query.expression; | ||
|
||
import com.google.common.collect.Lists; | ||
import org.apache.commons.compress.utils.Sets; | ||
import org.apache.druid.math.expr.Expr; | ||
import org.apache.druid.math.expr.ExprEval; | ||
import org.apache.druid.query.lookup.LookupExtractorFactoryContainer; | ||
import org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class LookupExprMacroTest extends MacroTestBase | ||
{ | ||
public LookupExprMacroTest() | ||
{ | ||
super( | ||
new LookupExprMacro(new LookupExtractorFactoryContainerProvider() | ||
{ | ||
@Override | ||
public Set<String> getAllLookupNames() | ||
{ | ||
return Sets.newHashSet("test_lookup"); | ||
} | ||
|
||
@Override | ||
public Optional<LookupExtractorFactoryContainer> get(String lookupName) | ||
{ | ||
return Optional.empty(); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
@Test | ||
public void testTooFewArgs() | ||
{ | ||
expectException(IllegalArgumentException.class, "Function[lookup] requires 2 to 3 arguments"); | ||
apply(Collections.emptyList()); | ||
} | ||
|
||
@Test | ||
public void testNonLiteralLookupName() | ||
{ | ||
expectException( | ||
IllegalArgumentException.class, | ||
"Function[lookup] second argument must be a registered lookup name" | ||
); | ||
apply(getArgs(Lists.newArrayList("1", new ArrayList<String>()))); | ||
} | ||
|
||
@Test | ||
public void testValidCalls() | ||
{ | ||
Assert.assertNotNull(apply(getArgs(Lists.newArrayList("1", "test_lookup")))); | ||
Assert.assertNotNull(apply(getArgs(Lists.newArrayList("null", "test_lookup")))); | ||
Assert.assertNotNull(apply(getArgs(Lists.newArrayList("1", "test_lookup", null)))); | ||
Assert.assertNotNull(apply(getArgs(Lists.newArrayList("1", "test_lookup", "N/A")))); | ||
} | ||
|
||
private List<Expr> getArgs(List<Object> args) | ||
{ | ||
return args.stream().map(a -> { | ||
if (a != null && a instanceof String) { | ||
return ExprEval.of(a.toString()).toExpr(); | ||
} | ||
return ExprEval.bestEffortOf(null).toExpr(); | ||
}).collect(Collectors.toList()); | ||
} | ||
} |
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