Skip to content

Commit

Permalink
rename alg -> algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
idegtiarenko committed Dec 12, 2024
1 parent c2811b7 commit 27a9042
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 63 deletions.
8 changes: 4 additions & 4 deletions docs/reference/esql/functions/kibana/definition/hash.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/esql/functions/parameters/hash.asciidoc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/esql/functions/signature/hash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/reference/esql/functions/types/hash.asciidoc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Hash extends EsqlScalarFunction {

public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Hash", Hash::new);

private final Expression alg;
private final Expression algorithm;
private final Expression input;

@FunctionInfo(
Expand All @@ -47,11 +47,11 @@ public class Hash extends EsqlScalarFunction {
)
public Hash(
Source source,
@Param(name = "alg", type = { "keyword", "text" }, description = "Hash algorithm to use.") Expression alg,
@Param(name = "algorithm", type = { "keyword", "text" }, description = "Hash algorithm to use.") Expression algorithm,
@Param(name = "input", type = { "keyword", "text" }, description = "Input to hash.") Expression input
) {
super(source, List.of(alg, input));
this.alg = alg;
super(source, List.of(algorithm, input));
this.algorithm = algorithm;
this.input = input;
}

Expand All @@ -62,7 +62,7 @@ private Hash(StreamInput in) throws IOException {
@Override
public void writeTo(StreamOutput out) throws IOException {
source().writeTo(out);
out.writeNamedWriteable(alg);
out.writeNamedWriteable(algorithm);
out.writeNamedWriteable(input);
}

Expand All @@ -82,7 +82,7 @@ protected TypeResolution resolveType() {
return new TypeResolution("Unresolved children");
}

TypeResolution resolution = isString(alg, sourceText(), FIRST);
TypeResolution resolution = isString(algorithm, sourceText(), FIRST);
if (resolution.unresolved()) {
return resolution;
}
Expand All @@ -92,28 +92,28 @@ protected TypeResolution resolveType() {

@Override
public boolean foldable() {
return alg.foldable() && input.foldable();
return algorithm.foldable() && input.foldable();
}

@Evaluator(warnExceptions = NoSuchAlgorithmException.class)
static BytesRef process(@Fixed(includeInToString = false, build = true) BreakingBytesRefBuilder scratch, BytesRef alg, BytesRef input)
static BytesRef process(@Fixed(includeInToString = false, build = true) BreakingBytesRefBuilder scratch, BytesRef algorithm, BytesRef input)
throws NoSuchAlgorithmException {
return hash(scratch, MessageDigest.getInstance(alg.utf8ToString()), input);
return hash(scratch, MessageDigest.getInstance(algorithm.utf8ToString()), input);
}

@Evaluator(extraName = "Constant")
static BytesRef processConstant(
@Fixed(includeInToString = false, build = true) BreakingBytesRefBuilder scratch,
@Fixed(build = true) MessageDigest alg,
@Fixed(build = true) MessageDigest algorithm,
BytesRef input
) {
return hash(scratch, alg, input);
return hash(scratch, algorithm, input);
}

private static BytesRef hash(BreakingBytesRefBuilder scratch, MessageDigest alg, BytesRef input) {
alg.reset();
alg.update(input.bytes, input.offset, input.length);
var digest = alg.digest();
private static BytesRef hash(BreakingBytesRefBuilder scratch, MessageDigest algorithm, BytesRef input) {
algorithm.reset();
algorithm.update(input.bytes, input.offset, input.length);
var digest = algorithm.digest();
scratch.clear();
scratch.grow(digest.length * 2);
appendUtf8HexDigest(scratch, digest);
Expand All @@ -135,23 +135,23 @@ private static void appendUtf8HexDigest(BreakingBytesRefBuilder scratch, byte[]

@Override
public EvalOperator.ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
if (alg.foldable()) {
if (algorithm.foldable()) {
try {
var md = MessageDigest.getInstance(((BytesRef) alg.fold()).utf8ToString());
var md = MessageDigest.getInstance(((BytesRef) algorithm.fold()).utf8ToString());
return new HashConstantEvaluator.Factory(
source(),
context -> new BreakingBytesRefBuilder(context.breaker(), "hash"),
context -> md,
toEvaluator.apply(input)
);
} catch (NoSuchAlgorithmException e) {
throw new InvalidArgumentException(e, "invalid alg for [{}]: {}", sourceText(), e.getMessage());
throw new InvalidArgumentException(e, "invalid algorithm for [{}]: {}", sourceText(), e.getMessage());
}
} else {
return new HashEvaluator.Factory(
source(),
context -> new BreakingBytesRefBuilder(context.breaker(), "hash"),
toEvaluator.apply(alg),
toEvaluator.apply(algorithm),
toEvaluator.apply(input)
);
}
Expand Down

0 comments on commit 27a9042

Please sign in to comment.