org.verdictdb.connection.StaticMetaData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of verdictdb-core Show documentation
Show all versions of verdictdb-core Show documentation
Platform-independent, interactive-speed data analytics system
/*
* Copyright 2018 University of Michigan
*
* 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 org.verdictdb.connection;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class StaticMetaData implements MetaDataProvider {
public static class TableInfo {
String schema;
String tablename;
public TableInfo(String schema, String tablename) {
this.schema = schema;
this.tablename = tablename;
}
public static TableInfo getTableInfo(String schema, String tablename) {
return new TableInfo(schema, tablename);
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
private String defaultSchema = "";
// The value pair: left is column name and right is its type
private HashMap>> tablesData = new HashMap<>();
private List schemas = new ArrayList<>();
private HashMap> tables = new HashMap<>();
// TODO: what is the difference from tableData?
private HashMap, List>> columns = new HashMap<>();
private HashMap, List> partitions = new HashMap<>();
public StaticMetaData() {}
public StaticMetaData(HashMap>> tablesData) {
this.tablesData = tablesData;
for (Map.Entry>> entry : tablesData.entrySet()) {
if (!schemas.contains(entry.getKey().schema)) {
schemas.add(entry.getKey().schema);
}
tables.get(entry.getKey().schema).add(entry.getKey().tablename);
columns.put(
new ImmutablePair<>(entry.getKey().schema, entry.getKey().tablename), entry.getValue());
}
}
public void addTableData(TableInfo table, List> column) {
tablesData.put(table, column);
if (!schemas.contains(table.schema)) {
schemas.add(table.schema);
tables.put(table.schema, new ArrayList());
}
tables.get(table.schema).add(table.tablename);
columns.put(new ImmutablePair<>(table.schema, table.tablename), column);
}
public void addPartition(TableInfo table, List column) {
partitions.put(new ImmutablePair<>(table.schema, table.tablename), column);
}
public void setDefaultSchema(String schema) {
defaultSchema = schema;
}
@Override
public List getSchemas() {
return schemas;
}
@Override
public List getTables(String schema) {
return tables.get(schema);
}
@Override
public List> getColumns(String schema, String table) {
List> nameAndType = new ArrayList<>();
List> nameAndIntType = columns.get(new ImmutablePair<>(schema, table));
for (Pair a : nameAndIntType) {
nameAndType.add(Pair.of(a.getLeft(), DataTypeConverter.typeName(a.getRight())));
}
return nameAndType;
}
@Override
public List getPartitionColumns(String schema, String table) {
return partitions.get(new ImmutablePair<>(schema, table));
}
public String getDefaultSchema() {
return defaultSchema;
}
public HashMap>> getTablesData() {
return tablesData;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy