diff --git a/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java b/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java index 596eda6f0a3f7..8a85b0fd599c3 100644 --- a/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java +++ b/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java @@ -433,41 +433,22 @@ public static DataType fromEs(String name) { } public static DataType fromJava(Object value) { - if (value == null) { - return NULL; - } - if (value instanceof Integer) { - return INTEGER; - } - if (value instanceof Long) { - return LONG; - } - if (value instanceof BigInteger) { - return UNSIGNED_LONG; - } - if (value instanceof Boolean) { - return BOOLEAN; - } - if (value instanceof Double) { - return DOUBLE; - } - if (value instanceof Float) { - return FLOAT; - } - if (value instanceof Byte) { - return BYTE; - } - if (value instanceof Short) { - return SHORT; - } - if (value instanceof ZonedDateTime) { - return DATETIME; - } - if (value instanceof String || value instanceof Character || value instanceof BytesRef) { - return KEYWORD; - } - - return null; + return switch (value) { + case null -> NULL; + case Integer i -> INTEGER; + case Long l -> LONG; + case BigInteger bigInteger -> UNSIGNED_LONG; + case Boolean b -> BOOLEAN; + case Double v -> DOUBLE; + case Float v -> FLOAT; + case Byte b -> BYTE; + case Short i -> SHORT; + case ZonedDateTime zonedDateTime -> DATETIME; + case String s -> KEYWORD; + case Character c -> KEYWORD; + case BytesRef bytesRef -> KEYWORD; + default -> null; + }; } public static boolean isUnsupported(DataType from) { diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java index 7ab25d43dd8cb..9ec0462d19702 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java @@ -483,59 +483,22 @@ protected LogicalPlan rule(LogicalPlan plan, AnalyzerContext context) { childrenOutput.addAll(output); } - if (plan instanceof Aggregate aggregate) { - return resolveAggregate(aggregate, childrenOutput); - } - - if (plan instanceof Drop d) { - return resolveDrop(d, childrenOutput); - } - - if (plan instanceof Rename r) { - return resolveRename(r, childrenOutput); - } - - if (plan instanceof Keep p) { - return resolveKeep(p, childrenOutput); - } - - if (plan instanceof Eval p) { - return resolveEval(p, childrenOutput); - } - - if (plan instanceof Enrich p) { - return resolveEnrich(p, childrenOutput); - } - - if (plan instanceof MvExpand p) { - return resolveMvExpand(p, childrenOutput); - } - - if (plan instanceof Lookup l) { - return resolveLookup(l, childrenOutput); - } - - if (plan instanceof LookupJoin j) { - return resolveLookupJoin(j); - } - - if (plan instanceof Insist i) { - return resolveInsist(i, childrenOutput, context.indexResolution()); - } - - if (plan instanceof Dedup dedup) { - return resolveDedup(dedup, childrenOutput); - } - - if (plan instanceof RrfScoreEval rrf) { - return resolveRrfScoreEval(rrf, childrenOutput); - } - - if (plan instanceof Rerank r) { - return resolveRerank(r, childrenOutput); - } - - return plan.transformExpressionsOnly(UnresolvedAttribute.class, ua -> maybeResolveAttribute(ua, childrenOutput)); + return switch (plan) { + case Aggregate aggregate -> resolveAggregate(aggregate, childrenOutput); + case Drop d -> resolveDrop(d, childrenOutput); + case Rename r -> resolveRename(r, childrenOutput); + case Keep p -> resolveKeep(p, childrenOutput); + case Eval p -> resolveEval(p, childrenOutput); + case Enrich p -> resolveEnrich(p, childrenOutput); + case MvExpand p -> resolveMvExpand(p, childrenOutput); + case Lookup l -> resolveLookup(l, childrenOutput); + case LookupJoin j -> resolveLookupJoin(j); + case Insist i -> resolveInsist(i, childrenOutput, context.indexResolution()); + case Dedup dedup -> resolveDedup(dedup, childrenOutput); + case RrfScoreEval rrf -> resolveRrfScoreEval(rrf, childrenOutput); + case Rerank r -> resolveRerank(r, childrenOutput); + default -> plan.transformExpressionsOnly(UnresolvedAttribute.class, ua -> maybeResolveAttribute(ua, childrenOutput)); + }; } private Aggregate resolveAggregate(Aggregate aggregate, List childrenOutput) { @@ -1286,7 +1249,7 @@ private static Expression cast(org.elasticsearch.xpack.esql.core.expression.func return processScalarOrGroupingFunction(f, registry); } if (f instanceof EsqlArithmeticOperation || f instanceof BinaryComparison) { - return processBinaryOperator((BinaryOperator) f); + return processBinaryOperator((BinaryOperator) f); } return f; } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java index 1e0c51b8fcab3..2fa827a8132b1 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java @@ -231,65 +231,40 @@ public LocalExecutionPlan plan(String description, FoldContext foldCtx, Physical } private PhysicalOperation plan(PhysicalPlan node, LocalExecutionPlannerContext context) { - if (node instanceof AggregateExec aggregate) { - return planAggregation(aggregate, context); - } else if (node instanceof FieldExtractExec fieldExtractExec) { - return planFieldExtractNode(fieldExtractExec, context); - } else if (node instanceof ExchangeExec exchangeExec) { - return planExchange(exchangeExec, context); - } else if (node instanceof TopNExec topNExec) { - return planTopN(topNExec, context); - } else if (node instanceof EvalExec eval) { - return planEval(eval, context); - } else if (node instanceof DissectExec dissect) { - return planDissect(dissect, context); - } else if (node instanceof GrokExec grok) { - return planGrok(grok, context); - } else if (node instanceof ProjectExec project) { - return planProject(project, context); - } else if (node instanceof FilterExec filter) { - return planFilter(filter, context); - } else if (node instanceof LimitExec limit) { - return planLimit(limit, context); - } else if (node instanceof MvExpandExec mvExpand) { - return planMvExpand(mvExpand, context); - } else if (node instanceof RerankExec rerank) { - return planRerank(rerank, context); - } else if (node instanceof ChangePointExec changePoint) { - return planChangePoint(changePoint, context); - } - // source nodes - else if (node instanceof EsQueryExec esQuery) { - return planEsQueryNode(esQuery, context); - } else if (node instanceof EsStatsQueryExec statsQuery) { - return planEsStats(statsQuery, context); - } else if (node instanceof LocalSourceExec localSource) { - return planLocal(localSource, context); - } else if (node instanceof ShowExec show) { - return planShow(show); - } else if (node instanceof ExchangeSourceExec exchangeSource) { - return planExchangeSource(exchangeSource, context); - } - // lookups and joins - else if (node instanceof EnrichExec enrich) { - return planEnrich(enrich, context); - } else if (node instanceof HashJoinExec join) { - return planHashJoin(join, context); - } else if (node instanceof LookupJoinExec join) { - return planLookupJoin(join, context); - } - // output - else if (node instanceof OutputExec outputExec) { - return planOutput(outputExec, context); - } else if (node instanceof ExchangeSinkExec exchangeSink) { - return planExchangeSink(exchangeSink, context); - } else if (node instanceof MergeExec mergeExec) { - return planMerge(mergeExec, context); - } else if (node instanceof RrfScoreEvalExec rrf) { - return planRrfScoreEvalExec(rrf, context); - } - - throw new EsqlIllegalArgumentException("unknown physical plan node [" + node.nodeName() + "]"); + return switch (node) { + case AggregateExec aggregate -> planAggregation(aggregate, context); + case FieldExtractExec fieldExtractExec -> planFieldExtractNode(fieldExtractExec, context); + case ExchangeExec exchangeExec -> planExchange(exchangeExec, context); + case TopNExec topNExec -> planTopN(topNExec, context); + case EvalExec eval -> planEval(eval, context); + case DissectExec dissect -> planDissect(dissect, context); + case GrokExec grok -> planGrok(grok, context); + case ProjectExec project -> planProject(project, context); + case FilterExec filter -> planFilter(filter, context); + case LimitExec limit -> planLimit(limit, context); + case MvExpandExec mvExpand -> planMvExpand(mvExpand, context); + case RerankExec rerank -> planRerank(rerank, context); + case ChangePointExec changePoint -> planChangePoint(changePoint, context); + + // source nodes + case EsQueryExec esQuery -> planEsQueryNode(esQuery, context); + case EsStatsQueryExec statsQuery -> planEsStats(statsQuery, context); + case LocalSourceExec localSource -> planLocal(localSource, context); + case ShowExec show -> planShow(show); + case ExchangeSourceExec exchangeSource -> planExchangeSource(exchangeSource, context); + + // lookups and joins + case EnrichExec enrich -> planEnrich(enrich, context); + case HashJoinExec join -> planHashJoin(join, context); + case LookupJoinExec join -> planLookupJoin(join, context); + + // output + case OutputExec outputExec -> planOutput(outputExec, context); + case ExchangeSinkExec exchangeSink -> planExchangeSink(exchangeSink, context); + case MergeExec mergeExec -> planMerge(mergeExec, context); + case RrfScoreEvalExec rrf -> planRrfScoreEvalExec(rrf, context); + case null, default -> throw new EsqlIllegalArgumentException("unknown physical plan node [" + node.nodeName() + "]"); + }; } private PhysicalOperation planRrfScoreEvalExec(RrfScoreEvalExec rrf, LocalExecutionPlannerContext context) {