io.trino.plugin.accumulo.conf.AccumuloTableProperties Maven / Gradle / Ivy
Show all versions of trino-accumulo Show documentation
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.accumulo.conf;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import io.trino.plugin.accumulo.serializers.AccumuloRowSerializer;
import io.trino.plugin.accumulo.serializers.LexicoderRowSerializer;
import io.trino.plugin.accumulo.serializers.StringRowSerializer;
import io.trino.spi.TrinoException;
import io.trino.spi.session.PropertyMetadata;
import io.trino.spi.type.VarcharType;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import static com.google.common.base.Preconditions.checkState;
import static io.trino.spi.StandardErrorCode.INVALID_TABLE_PROPERTY;
import static io.trino.spi.session.PropertyMetadata.booleanProperty;
import static io.trino.spi.session.PropertyMetadata.stringProperty;
import static java.util.Objects.requireNonNull;
/**
* Class contains all table properties for the Accumulo connector. Used when creating a table:
*
* CREATE TABLE foo (a VARCHAR, b INT)
* WITH (column_mapping = 'b:md:b', external = true);
*/
public final class AccumuloTableProperties
{
public static final String COLUMN_MAPPING = "column_mapping";
public static final String INDEX_COLUMNS = "index_columns";
public static final String EXTERNAL = "external";
public static final String LOCALITY_GROUPS = "locality_groups";
public static final String ROW_ID = "row_id";
public static final String SERIALIZER = "serializer";
public static final String SCAN_AUTHS = "scan_auths";
private static final Splitter COLON_SPLITTER = Splitter.on(':').trimResults();
private static final Splitter COMMA_SPLITTER = Splitter.on(',').omitEmptyStrings().trimResults();
private static final Splitter PIPE_SPLITTER = Splitter.on('|').omitEmptyStrings().trimResults();
private final List> tableProperties;
public AccumuloTableProperties()
{
PropertyMetadata s1 = stringProperty(
COLUMN_MAPPING,
"Comma-delimited list of column metadata: col_name:col_family:col_qualifier,[...]. Required for external tables. Not setting this property results in auto-generated column names.",
null,
false);
PropertyMetadata s2 = stringProperty(
INDEX_COLUMNS,
"A comma-delimited list of Trino columns that are indexed in this table's corresponding index table. Default is no indexed columns.",
"",
false);
PropertyMetadata s3 = booleanProperty(
EXTERNAL,
"If true, Trino will only do metadata operations for the table. Else, Trino will create and drop Accumulo tables where appropriate. Default false.",
false,
false);
PropertyMetadata s4 = stringProperty(
LOCALITY_GROUPS,
"List of locality groups to set on the Accumulo table. Only valid on internal tables. String format is locality group name, colon, comma delimited list of Trino column names in the group. Groups are delimited by pipes. Example: group1:colA,colB,colC|group2:colD,colE,colF|etc.... Default is no locality groups.",
null,
false);
PropertyMetadata s5 = stringProperty(
ROW_ID,
"Trino column name that maps to the Accumulo row ID. Default is the first column.",
null,
false);
PropertyMetadata s6 = new PropertyMetadata<>(
SERIALIZER,
"Serializer for Accumulo data encodings. Can either be 'default', 'string', 'lexicoder', or a Java class name. Default is 'default', i.e. the value from AccumuloRowSerializer.getDefault(), i.e. 'lexicoder'.",
VarcharType.VARCHAR, String.class,
AccumuloRowSerializer.getDefault().getClass().getName(),
false,
x -> x.equals("default")
? AccumuloRowSerializer.getDefault().getClass().getName()
: (x.equals("string") ? StringRowSerializer.class.getName()
: (x.equals("lexicoder")
? LexicoderRowSerializer.class.getName()
: (String) x)),
object -> object);
PropertyMetadata s7 = stringProperty(
SCAN_AUTHS,
"Scan-time authorizations set on the batch scanner. Default is all scan authorizations for the user",
null,
false);
tableProperties = ImmutableList.of(s1, s2, s3, s4, s5, s6, s7);
}
public List> getTableProperties()
{
return tableProperties;
}
/**
* Gets the value of the column_mapping property, or Optional.empty() if not set.
*
* Parses the value into a map of Trino column name to a pair of strings, the Accumulo column family and qualifier.
*
* @param tableProperties The map of table properties
* @return The column mapping, Trino name to (accumulo column family, qualifier)
*/
public static Optional