org.elasticsearch.xpack.esql.plan.logical.RegexExtract 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.plan.logical;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.expression.NameId;
import org.elasticsearch.xpack.esql.core.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.esql.core.plan.logical.UnaryPlan;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.plan.GeneratingPlan;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static org.elasticsearch.xpack.esql.expression.NamedExpressions.mergeOutputAttributes;
public abstract class RegexExtract extends UnaryPlan implements GeneratingPlan {
protected final Expression input;
protected final List extractedFields;
protected RegexExtract(Source source, LogicalPlan child, Expression input, List extracted) {
super(source, child);
this.input = input;
this.extractedFields = extracted;
}
@Override
public boolean expressionsResolved() {
return input.resolved();
}
@Override
public List output() {
return mergeOutputAttributes(extractedFields, child().output());
}
public Expression input() {
return input;
}
/**
* Upon parsing, these are named according to the {@link Dissect} or {@link Grok} pattern, but can be renamed without changing the
* pattern.
*/
public List extractedFields() {
return extractedFields;
}
@Override
public List generatedAttributes() {
return extractedFields;
}
List renameExtractedFields(List newNames) {
checkNumberOfNewNames(newNames);
List renamedExtractedFields = new ArrayList<>(extractedFields.size());
for (int i = 0; i < newNames.size(); i++) {
Attribute extractedField = extractedFields.get(i);
String newName = newNames.get(i);
if (extractedField.name().equals(newName)) {
renamedExtractedFields.add(extractedField);
} else {
renamedExtractedFields.add(extractedFields.get(i).withName(newNames.get(i)).withId(new NameId()));
}
}
return renamedExtractedFields;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (super.equals(o) == false) return false;
RegexExtract that = (RegexExtract) o;
return Objects.equals(input, that.input) && Objects.equals(extractedFields, that.extractedFields);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), input, extractedFields);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy