org.elasticsearch.xpack.esql.analysis.PreAnalyzer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of x-pack-esql Show documentation
Show all versions of x-pack-esql Show documentation
The plugin that powers ESQL for Elasticsearch
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.esql.analysis;
import org.elasticsearch.xpack.esql.core.analyzer.TableInfo;
import org.elasticsearch.xpack.esql.core.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
import org.elasticsearch.xpack.esql.plan.logical.EsqlUnresolvedRelation;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.emptyList;
public class PreAnalyzer {
public static class PreAnalysis {
public static final PreAnalysis EMPTY = new PreAnalysis(emptyList(), emptyList());
public final List indices;
public final List enriches;
public PreAnalysis(List indices, List enriches) {
this.indices = indices;
this.enriches = enriches;
}
}
public PreAnalysis preAnalyze(LogicalPlan plan) {
if (plan.analyzed()) {
return PreAnalysis.EMPTY;
}
return doPreAnalyze(plan);
}
protected PreAnalysis doPreAnalyze(LogicalPlan plan) {
List indices = new ArrayList<>();
List unresolvedEnriches = new ArrayList<>();
plan.forEachUp(EsqlUnresolvedRelation.class, p -> { indices.add(new TableInfo(p.table(), p.frozen())); });
plan.forEachUp(Enrich.class, unresolvedEnriches::add);
// mark plan as preAnalyzed (if it were marked, there would be no analysis)
plan.forEachUp(LogicalPlan::setPreAnalyzed);
return new PreAnalysis(indices, unresolvedEnriches);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy