Skip to content

Commit

Permalink
additional test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
idegtiarenko committed Dec 5, 2024
1 parent 48d4dd1 commit 1adfc89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import java.util.HexFormat;
import java.util.List;

import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isString;

public class Hash extends EsqlScalarFunction {

public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Hash", Hash::new);
Expand Down Expand Up @@ -68,6 +72,20 @@ public DataType dataType() {
return DataType.KEYWORD;
}

@Override
protected TypeResolution resolveType() {
if (childrenResolved() == false) {
return new TypeResolution("Unresolved children");
}

TypeResolution resolution = isString(alg, sourceText(), FIRST);
if (resolution.unresolved()) {
return resolution;
}

return isString(input, sourceText(), SECOND);
}

@Override
public boolean foldable() {
return alg.foldable() && input.foldable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Iterable<Object[]> parameters() {
for (String alg : List.of("MD5", "SHA", "SHA-224", "SHA-256", "SHA-384", "SHA-512")) {
cases.addAll(createTestCases(alg));
}
return parameterSuppliersFromTypedData(cases);
return parameterSuppliersFromTypedDataWithDefaultChecks(true, cases, (v, p) -> "string");
}

private static List<TestCaseSupplier> createTestCases(String alg) {
Expand Down

0 comments on commit 1adfc89

Please sign in to comment.