org.elasticsearch.xpack.esql.planner.DefaultLayout 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.planner;
import org.elasticsearch.xpack.esql.core.expression.NameId;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
class DefaultLayout implements Layout {
private final Map layout;
private final int numberOfChannels;
DefaultLayout(Map layout, int numberOfChannels) {
this.layout = layout;
this.numberOfChannels = numberOfChannels;
}
@Override
public ChannelAndType get(NameId id) {
return layout.get(id);
}
/**
* @return the total number of channels in the layout.
*/
@Override
public int numberOfChannels() {
return numberOfChannels;
}
@Override
public List inverse() {
List inverse = new ArrayList<>(numberOfChannels);
for (int i = 0; i < numberOfChannels; i++) {
inverse.add(null);
}
for (Map.Entry entry : layout.entrySet()) {
ChannelSet set = inverse.get(entry.getValue().channel());
if (set == null) {
set = new ChannelSet(new HashSet<>(), entry.getValue().type());
inverse.set(entry.getValue().channel(), set);
} else {
if (set.type() != entry.getValue().type()) {
throw new IllegalArgumentException();
}
}
set.nameIds().add(entry.getKey());
}
return inverse;
}
/**
* @return creates a builder to append to this layout.
*/
@Override
public Layout.Builder builder() {
return new Builder(inverse());
}
@Override
public String toString() {
return "Layout{layout=" + layout + ", numberOfChannels=" + numberOfChannels + '}';
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy