org.apache.hadoop.hive.metastore.api.Table - java examples

Here are the examples of the java api org.apache.hadoop.hive.metastore.api.Table taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : TestUtils.java
Copyright Apache License 2.0
Author : HotelsDotCom
public static TableAndMetadata newTableAndMetadata(String database, String tableName) {
    Table table = newTable(database, tableName);
    return new TableAndMetadata(Warehouse.getQualifiedName(table), table.getSd().getLocation(), table);
}

19 View Complete Implementation : ThriftHiveMetastoreClient.java
Copyright Apache License 2.0
Author : airbnb
/**
 * TODO.
 *
 * @param dbName TODO
 * @param tableName TODO
 * @param table TODO
 *
 * @throws HiveMetastoreException TODO
 */
public synchronized void alterTable(String dbName, String tableName, Table table) throws HiveMetastoreException {
    try {
        connectIfNeeded();
        client.alter_table(dbName, tableName, table);
    } catch (TException e) {
        close();
        throw new HiveMetastoreException(e);
    }
}

19 View Complete Implementation : Replica.java
Copyright Apache License 2.0
Author : HotelsDotCom
private boolean isUnparreplacedioned(Table table) {
    return table.getParreplacedionKeysSize() == 0;
}

19 View Complete Implementation : TableTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
public clreplaced TableTransformationTest {

    private Table table;

    @Before
    public void init() {
        table = new Table();
        table.setDbName("database");
        table.setTableName("table");
        table.setTableType("type");
        Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>();
        userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo()));
        PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet();
        privileges.setUserPrivileges(userPrivileges);
        table.setPrivileges(privileges);
        StorageDescriptor storageDescriptor = new StorageDescriptor();
        storageDescriptor.setCols(Arrays.asList(new FieldSchema("a", "int", null)));
        storageDescriptor.setInputFormat("input_format");
        storageDescriptor.setOutputFormat("output_format");
        storageDescriptor.setSerdeInfo(new SerDeInfo("serde", "lib", new HashMap<String, String>()));
        storageDescriptor.setSkewedInfo(new SkewedInfo());
        storageDescriptor.setParameters(new HashMap<String, String>());
        storageDescriptor.setLocation("database/table/");
        table.setSd(storageDescriptor);
        Map<String, String> parameters = new HashMap<>();
        parameters.put("com.company.parameter", "abc");
        table.setParameters(parameters);
    }

    @Test
    public void idenreplacedy() {
        Table tableCopy = table.deepCopy();
        Table transformedTable = TableTransformation.IDENreplacedY.transform(table);
        // original table is untouched
        replacedertThat(table, is(tableCopy));
        // returned table is verbatim copy of table
        replacedertThat(transformedTable, is(tableCopy));
        replacedertThat(transformedTable == table, is(true));
    }
}

19 View Complete Implementation : HiveDifferences.java
Copyright Apache License 2.0
Author : HotelsDotCom
@VisibleForTesting
static TableAndMetadata sourceTableToTableAndMetadata(Table sourceTable) {
    return new TableAndMetadata(Warehouse.getQualifiedName(sourceTable), normaliseLocation(sourceTable.getSd().getLocation()), sourceTable);
}

19 View Complete Implementation : ThriftHiveMetastoreClient.java
Copyright Apache License 2.0
Author : airbnb
/**
 * TODO.
 *
 * @param table TODO
 *
 * @throws HiveMetastoreException TODO
 */
public synchronized void createTable(Table table) throws HiveMetastoreException {
    try {
        connectIfNeeded();
        client.create_table(table);
    } catch (TException e) {
        close();
        throw new HiveMetastoreException(e);
    }
}

19 View Complete Implementation : HiveDifferences.java
Copyright Apache License 2.0
Author : HotelsDotCom
@VisibleForTesting
static TableAndMetadata replicaTableToTableAndMetadata(Table replicaTable) {
    return new TableAndMetadata(replicaTable.getParameters().get(SOURCE_TABLE.parameterName()), normaliseLocation(replicaTable.getParameters().get(SOURCE_LOCATION.parameterName())), replicaTable);
}

19 View Complete Implementation : ReplicationUtils.java
Copyright Apache License 2.0
Author : airbnb
/**
 * Check if the schema between two tables match.
 *
 * @param srcTable source table
 * @param destTable destination table
 * @return whether or not the schemas of the tables match
 */
public static boolean schemasMatch(Table srcTable, Table destTable) {
    return srcTable.getSd().getCols().equals(destTable.getSd().getCols()) && srcTable.getParreplacedionKeys().equals(destTable.getParreplacedionKeys());
}

19 View Complete Implementation : Source.java
Copyright Apache License 2.0
Author : HotelsDotCom
public SourceLocationManager getLocationManager(Table table, String eventId) throws IOException {
    if (MetaStoreUtils.isView(table)) {
        return new ViewLocationManager();
    }
    return new HdfsSnapshotLocationManager(getHiveConf(), eventId, table, snapshotsDisabled, sourceTableLocation, sourceCatalogListener);
}

19 View Complete Implementation : ThriftHiveMetastoreClient.java
Copyright Apache License 2.0
Author : airbnb
/**
 * TODO.
 *
 * @param dbName TODO
 * @param tableName TODO
 * @return TODO
 *
 * @throws HiveMetastoreException TODO
 */
public boolean isParreplacedioned(String dbName, String tableName) throws HiveMetastoreException {
    Table table = getTable(dbName, tableName);
    return table != null && table.getParreplacedionKeys().size() > 0;
}

19 View Complete Implementation : EventUtils.java
Copyright Apache License 2.0
Author : HotelsDotCom
public static EventTable toEventTable(Table sourceTable) {
    if (sourceTable == null) {
        return null;
    }
    return new EventTable(FieldSchemaUtils.getFieldNames(sourceTable.getParreplacedionKeys()), LocationUtils.hasLocation(sourceTable) ? LocationUtils.locationAsUri(sourceTable) : null);
}

19 View Complete Implementation : TableAndMetadata.java
Copyright Apache License 2.0
Author : HotelsDotCom
public clreplaced TableAndMetadata {

    private final String sourceTable;

    private final String sourceLocation;

    private final Table table;

    public TableAndMetadata(String sourceTable, String sourceLocation, Table table) {
        this.sourceTable = sourceTable;
        this.sourceLocation = sourceLocation;
        this.table = table;
    }

    public String getSourceTable() {
        return sourceTable;
    }

    public String getSourceLocation() {
        return sourceLocation;
    }

    public Table getTable() {
        return table;
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this).add("sourceTable", sourceTable).add("sourceLocation", sourceLocation).add("table", table).toString();
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(sourceTable, sourceLocation, table);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClreplaced() != obj.getClreplaced()) {
            return false;
        }
        TableAndMetadata other = (TableAndMetadata) obj;
        return Objects.equal(sourceTable, other.sourceTable) && Objects.equal(sourceLocation, other.sourceLocation) && Objects.equal(table, other.table);
    }
}

19 View Complete Implementation : Source.java
Copyright Apache License 2.0
Author : HotelsDotCom
public SourceLocationManager getLocationManager(Table table, List<Parreplacedion> parreplacedions, String eventId, Map<String, Object> copierOptions) throws IOException {
    if (MetaStoreUtils.isView(table)) {
        return new ViewLocationManager();
    }
    HdfsSnapshotLocationManager hdfsSnapshotLocationManager = new HdfsSnapshotLocationManager(getHiveConf(), eventId, table, parreplacedions, snapshotsDisabled, sourceTableLocation, sourceCatalogListener);
    boolean ignoreMissingFolder = MapUtils.getBooleanValue(copierOptions, CopierOptions.IGNORE_MISSING_PARreplacedION_FOLDER_ERRORS, false);
    if (ignoreMissingFolder) {
        return new FilterMissingParreplacedionsLocationManager(hdfsSnapshotLocationManager, getHiveConf());
    }
    return hdfsSnapshotLocationManager;
}

18 View Complete Implementation : TableTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void idenreplacedy() {
    Table tableCopy = table.deepCopy();
    Table transformedTable = TableTransformation.IDENreplacedY.transform(table);
    // original table is untouched
    replacedertThat(table, is(tableCopy));
    // returned table is verbatim copy of table
    replacedertThat(transformedTable, is(tableCopy));
    replacedertThat(transformedTable == table, is(true));
}

18 View Complete Implementation : HiveObjectUtils.java
Copyright Apache License 2.0
Author : HotelsDotCom
public static Table updateSerDeUrl(Table table, String parameter, String url) {
    updateSerDeUrl(table.getParameters(), table.getSd().getSerdeInfo().getParameters(), parameter, url);
    return table;
}

18 View Complete Implementation : TableAndStatistics.java
Copyright Apache License 2.0
Author : HotelsDotCom
public clreplaced TableAndStatistics {

    private final Table table;

    private final ColumnStatistics statistics;

    public TableAndStatistics(Table table, ColumnStatistics statistics) {
        this.table = table;
        this.statistics = statistics;
    }

    public Table getTable() {
        return table;
    }

    public ColumnStatistics getStatistics() {
        return statistics;
    }
}

18 View Complete Implementation : MockHiveMetastoreClient.java
Copyright Apache License 2.0
Author : airbnb
private String getParreplacedionName(Table table, List<String> values) {
    StringBuilder sb = new StringBuilder();
    int index = 0;
    for (FieldSchema fs : table.getParreplacedionKeys()) {
        if (index > 0) {
            sb.append("/");
        }
        sb.append(fs.getName());
        sb.append("=");
        sb.append(values.get(index));
        index++;
    }
    return sb.toString();
}

18 View Complete Implementation : AvroSerDeTableTransformation.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Override
public Table transform(Table table) {
    if (avroTransformationSpecified()) {
        table = apply(table, avroDestination(getAvroSchemaDestinationFolder(), getEventId(), getTableLocation()));
    }
    return table;
}

18 View Complete Implementation : IntegrationTestHelper.java
Copyright Apache License 2.0
Author : HotelsDotCom
void createParreplacedionedView() throws Exception {
    Table view = TestUtils.createParreplacedionedView(metaStoreClient, DATABASE, SOURCE_PARreplacedIONED_VIEW, PARreplacedIONED_TABLE);
    metaStoreClient.add_parreplacedions(Arrays.asList(newViewParreplacedion(view, Arrays.asList("Europe", "UK")), newViewParreplacedion(view, Arrays.asList("Asia", "China"))));
}

18 View Complete Implementation : HiveObjectUtils.java
Copyright Apache License 2.0
Author : HotelsDotCom
public static String getParameter(Table table, String parameter) {
    return getParameter(table.getParameters(), table.getSd().getSerdeInfo().getParameters(), parameter);
}

18 View Complete Implementation : TableParametersTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@RunWith(MockitoJUnitRunner.clreplaced)
public clreplaced TableParametersTransformationTest {

    private static final String KEY = "key";

    private static final String VALUE = "value";

    private static final String OVERRIDE_KEY = "override_key";

    private static final String OVERRIDE_VALUE = "override_value";

    private static final String SECOND_OVERRIDE_KEY = "second_override_key";

    private static final String SECOND_OVERRIDE_VALUE = "second_override_value";

    private static final String EVENT_ID = "event_id";

    private Table table = new Table();

    private TableParametersTransformation transformation;

    @Before
    public void init() {
        Map<String, String> tableProperties = new HashMap<>();
        tableProperties.put(KEY, VALUE);
        Map<String, Object> options = new HashMap<>();
        options.put(CircusTrainTransformOptions.TABLE_PROPERTIES, tableProperties);
        TransformOptions transformOptions = new TransformOptions();
        transformOptions.setTransformOptions(options);
        transformation = new TableParametersTransformation(transformOptions);
    }

    @Test
    public void typical() {
        Table transformedTable = transformation.transform(table);
        Map<String, String> tableParameters = transformedTable.getParameters();
        replacedertThat(tableParameters.size(), is(1));
        replacedertThat(tableParameters.get(KEY), is(VALUE));
    }

    @Test
    public void typicalImmutableTableParameters() {
        table.setParameters(Collections.EMPTY_MAP);
        Table transformedTable = transformation.transform(table);
        Map<String, String> tableParameters = transformedTable.getParameters();
        replacedertThat(tableParameters.size(), is(1));
        replacedertThat(tableParameters.get(KEY), is(VALUE));
    }

    @Test
    public void typicalWithTableParameters() {
        Map<String, String> parameters = new HashMap<>();
        parameters.put("old_key", "old_value");
        table.setParameters(parameters);
        Table transformedTable = transformation.transform(table);
        Map<String, String> tableParameters = transformedTable.getParameters();
        replacedertThat(tableParameters.size(), is(2));
        replacedertThat(tableParameters.get("old_key"), is("old_value"));
        replacedertThat(tableParameters.get(KEY), is(VALUE));
    }

    @Test
    public void transformationParametersOverwriteTableParameters() {
        Map<String, String> parameters = new HashMap<>();
        parameters.put(KEY, "old_value");
        table.setParameters(parameters);
        Table transformedTable = transformation.transform(table);
        Map<String, String> tableParameters = transformedTable.getParameters();
        replacedertThat(tableParameters.size(), is(1));
        replacedertThat(tableParameters.get(KEY), is(VALUE));
    }

    @Test
    public void typicalOverride() {
        transformation.tableReplicationStart(createEventTableReplication(OVERRIDE_KEY, OVERRIDE_VALUE), EVENT_ID);
        Table transformedTable = transformation.transform(table);
        Map<String, String> tableParameters = transformedTable.getParameters();
        replacedertThat(tableParameters.size(), is(1));
        replacedertThat(tableParameters.get(OVERRIDE_KEY), is(OVERRIDE_VALUE));
    }

    @Test
    public void typicalTwoReplicationsBothOverride() {
        transformation.tableReplicationStart(createEventTableReplication(OVERRIDE_KEY, OVERRIDE_VALUE), EVENT_ID);
        transformation.transform(table);
        replacedertThat(table.getParameters().size(), is(1));
        replacedertThat(table.getParameters().get(OVERRIDE_KEY), is(OVERRIDE_VALUE));
        transformation.tableReplicationStart(createEventTableReplication(SECOND_OVERRIDE_KEY, SECOND_OVERRIDE_VALUE), EVENT_ID);
        Table transformedTable = transformation.transform(new Table());
        Map<String, String> tableParameters = transformedTable.getParameters();
        replacedertThat(tableParameters.size(), is(1));
        replacedertThat(tableParameters.get(SECOND_OVERRIDE_KEY), is(SECOND_OVERRIDE_VALUE));
    }

    @Test
    public void typicalTwoReplicationsFirstOverride() {
        transformation.tableReplicationStart(createEventTableReplication(OVERRIDE_KEY, OVERRIDE_VALUE), EVENT_ID);
        transformation.transform(table);
        replacedertThat(table.getParameters().size(), is(1));
        replacedertThat(table.getParameters().get(OVERRIDE_KEY), is(OVERRIDE_VALUE));
        transformation.tableReplicationStart(createEventTableReplication(Collections.EMPTY_MAP), EVENT_ID);
        Table transformedTable = transformation.transform(new Table());
        Map<String, String> tableParameters = transformedTable.getParameters();
        replacedertThat(tableParameters.size(), is(1));
        replacedertThat(tableParameters.get(KEY), is(VALUE));
    }

    @Test
    public void typicalTwoReplicationsSecondOverride() {
        transformation.tableReplicationStart(createEventTableReplication(Collections.EMPTY_MAP), EVENT_ID);
        transformation.transform(table);
        replacedertThat(table.getParameters().size(), is(1));
        replacedertThat(table.getParameters().get(KEY), is(VALUE));
        transformation.tableReplicationStart(createEventTableReplication(SECOND_OVERRIDE_KEY, SECOND_OVERRIDE_VALUE), EVENT_ID);
        Table transformedTable = transformation.transform(new Table());
        Map<String, String> tableParameters = transformedTable.getParameters();
        replacedertThat(tableParameters.size(), is(1));
        replacedertThat(tableParameters.get(SECOND_OVERRIDE_KEY), is(SECOND_OVERRIDE_VALUE));
    }

    @Test
    public void tableReplicationOverridesNullDefault() {
        transformation = new TableParametersTransformation(new TransformOptions());
        transformation.tableReplicationStart(createEventTableReplication(OVERRIDE_KEY, OVERRIDE_VALUE), EVENT_ID);
        transformation.transform(table);
        replacedertThat(table.getParameters().size(), is(1));
        replacedertThat(table.getParameters().get(OVERRIDE_KEY), is(OVERRIDE_VALUE));
    }

    @Test
    public void noTransformations() {
        Map<String, String> parameters = new HashMap<>();
        parameters.put(KEY, VALUE);
        table.setParameters(parameters);
        transformation = new TableParametersTransformation(new TransformOptions());
        transformation.tableReplicationStart(createEventTableReplication(null), EVENT_ID);
        transformation.transform(table);
        replacedertThat(table.getParameters().size(), is(1));
        replacedertThat(table.getParameters().get(KEY), is(VALUE));
    }

    private EventTableReplication createEventTableReplication(String overrideKey, String overrideValue) {
        Map<String, Object> transformOptions = new HashMap<>();
        Map<String, Object> tableParametersOptions = new HashMap<>();
        tableParametersOptions.put(overrideKey, overrideValue);
        transformOptions.put(CircusTrainTransformOptions.TABLE_PROPERTIES, tableParametersOptions);
        return createEventTableReplication(transformOptions);
    }

    private EventTableReplication createEventTableReplication(Map<String, Object> transformOptions) {
        return new EventTableReplication(null, null, null, null, transformOptions);
    }
}

18 View Complete Implementation : HiveObjectUtilsTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void getParameterFromTableWhichIsntSetReturnsNull() {
    Table table = newTable();
    replacedertThat(HiveObjectUtils.getParameter(table, AVRO_SCHEMA_URL_PARAMETER), is(nullValue()));
}

18 View Complete Implementation : HiveObjectUtilsTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void getParameterFromTablesSerDeProperties() {
    Table table = newTable();
    table.getSd().getSerdeInfo().getParameters().put(AVRO_SCHEMA_URL_PARAMETER, "test");
    replacedertThat(HiveObjectUtils.getParameter(table, AVRO_SCHEMA_URL_PARAMETER), is("test"));
}

17 View Complete Implementation : HiveEndpoint.java
Copyright Apache License 2.0
Author : HotelsDotCom
private List<String> getColumnNames(Table table) {
    List<FieldSchema> fields = table.getSd().getCols();
    List<String> columnNames = new ArrayList<>(fields.size());
    for (FieldSchema field : fields) {
        columnNames.add(field.getName());
    }
    return columnNames;
}

17 View Complete Implementation : ViewTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void transform() {
    Table transformedTable = transformation.transform(table);
    replacedertThat(transformedTable, is(not(table)));
    verify(translator).translate(QUALIFIED_NAME, ORIGINAL_HQL);
    verify(translator).translate(QUALIFIED_NAME, EXPANDED_HQL);
    replacedertThat(transformedTable.getViewOriginalText(), is(ORIGINAL_TRANSLATED_HQL));
    replacedertThat(transformedTable.getViewExpandedText(), is(EXPANDED_TRANSLATED_HQL));
}

17 View Complete Implementation : IntegrationTestTransformation.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Override
public Table transform(Table table) {
    if (table.getParameters().get("circus.train.test.transformation") != null) {
        table.putToParameters("table.transformed", "true");
    }
    return table;
}

17 View Complete Implementation : HiveObjectUtilsTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void getParameterFromTablePropertiesWhenSerDePropertiesAreAlsoSetInTable() {
    Table table = newTable();
    table.getParameters().put(AVRO_SCHEMA_URL_PARAMETER, "test");
    table.getSd().getSerdeInfo().getParameters().put(AVRO_SCHEMA_URL_PARAMETER, "foo");
    replacedertThat(HiveObjectUtils.getParameter(table, AVRO_SCHEMA_URL_PARAMETER), is("test"));
}

17 View Complete Implementation : AvroSerDeTableTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void transformNoSourceUrl() throws Exception {
    EventReplicaTable eventReplicaTable = new EventReplicaTable("db", "table", "location");
    when(tableReplicationEvent.getReplicaTable()).thenReturn(eventReplicaTable);
    transformation.tableReplicationStart(tableReplicationEvent, "eventId");
    Table result = transformation.transform(table);
    verifyZeroInteractions(schemaCopier);
    replacedertThat(result, is(newTable()));
}

17 View Complete Implementation : ReplicationJobFactory.java
Copyright Apache License 2.0
Author : airbnb
/**
 * Create a mapping from a Hive object specification to the Thrift Hive Table object.
 *
 * @param tables tables to include in the map
 * @return a map from the Hive object specification to the Thrift Hive Table object
 */
private Map<HiveObjectSpec, Table> createTableLookupMap(List<Table> tables) {
    // Create a map from the table spec to the table object. We'll need this
    // for getting the table that a parreplacedion belongs to
    Map<HiveObjectSpec, Table> specToTable = new HashMap<>();
    for (Table table : tables) {
        HiveObjectSpec spec = new HiveObjectSpec(table);
        specToTable.put(spec, table);
    }
    return specToTable;
}

17 View Complete Implementation : ReplicationUtils.java
Copyright Apache License 2.0
Author : airbnb
/**
 * Return the last modified time of a table.
 */
public static Long getLastModifiedTime(Table table) {
    if (table == null) {
        return null;
    }
    Map<String, String> parameters = table.getParameters();
    return getLastModifiedTime(parameters);
}

17 View Complete Implementation : HiveObjectUtilsTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void getParameterFromTablesTableProperties() {
    Table table = newTable();
    table.getParameters().put(AVRO_SCHEMA_URL_PARAMETER, "test");
    replacedertThat(HiveObjectUtils.getParameter(table, AVRO_SCHEMA_URL_PARAMETER), is("test"));
}

17 View Complete Implementation : ReplicationUtils.java
Copyright Apache License 2.0
Author : airbnb
/**
 * Get the data location of a Hive table.
 *
 * @param table Thrift Hive table
 * @return the data location of the given table, if present
 */
public static Optional<Path> getLocation(Table table) {
    if (table == null || table.getSd() == null || table.getSd().getLocation() == null) {
        return Optional.empty();
    } else {
        return Optional.ofNullable(new Path(table.getSd().getLocation()));
    }
}

17 View Complete Implementation : HiveUtils.java
Copyright Apache License 2.0
Author : airbnb
/**
 * Checks to see if a table is a view.
 *
 * @param table table to check
 * @return true if the given table is a view.
 */
public static boolean isView(Table table) {
    return TableType.VIRTUAL_VIEW.name().equals(table.getTableType());
}

17 View Complete Implementation : TableParametersTransformation.java
Copyright Apache License 2.0
Author : HotelsDotCom
private Map<String, String> mergeTableParameters(Map<String, String> tableParameters, Table table) {
    Map<String, String> parameters;
    if (table.getParameters() != null) {
        parameters = new LinkedHashMap<>(table.getParameters());
    } else {
        parameters = new LinkedHashMap<>();
    }
    parameters.putAll(tableParameters);
    return parameters;
}

17 View Complete Implementation : ViewTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void skipTables() {
    when(table.getTableType()).thenReturn(TableType.EXTERNAL_TABLE.name());
    Table transformedTable = transformation.transform(table);
    replacedertThat(transformedTable, is(table));
}

17 View Complete Implementation : DiffUtils.java
Copyright Apache License 2.0
Author : HotelsDotCom
public static Diff<Object, Object> compareParameter(Table replicaTable, CircusTrainTableParameter parameter, String expectedValue) {
    return compareParameter(replicaTable.getParameters(), parameter, expectedValue);
}

17 View Complete Implementation : ReplicationUtils.java
Copyright Apache License 2.0
Author : airbnb
/**
 * Remove (or set to 0) fields in the table object that should not be compared.
 *
 * @param table the table to remove non-comparable fields
 * @return the table with non-comparable fields removed
 */
public static Table stripNonComparables(Table table) {
    Table newTable = new Table(table);
    newTable.setCreateTime(0);
    newTable.setLastAccessTime(0);
    return newTable;
}

17 View Complete Implementation : CompositeTableTransformation.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Override
public Table transform(Table table) {
    Table transformedTable = table;
    for (TableTransformation tableTransformation : tableTransformations) {
        transformedTable = tableTransformation.transform(transformedTable);
    }
    return transformedTable;
}

17 View Complete Implementation : ThriftLogReplicationFilter.java
Copyright Apache License 2.0
Author : airbnb
@Override
public boolean accept(Table table, NamedParreplacedion parreplacedion) {
    return true;
}

17 View Complete Implementation : TableAndMetadataComparatorTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
private static TableAndMetadata replicaTableAndMetadata(TableAndMetadata source, String tableName) {
    Table replica = newTable(source.getTable().getDbName(), tableName);
    setCircusTrainSourceParameters(source.getTable(), replica);
    return new TableAndMetadata(source.getSourceTable(), source.getSourceLocation(), replica);
}

17 View Complete Implementation : RemoveThriftEntriesReplicationFilter.java
Copyright Apache License 2.0
Author : airbnb
@Override
public boolean accept(Table table, NamedParreplacedion parreplacedion) {
    return true;
}

17 View Complete Implementation : IntegrationTestHelper.java
Copyright Apache License 2.0
Author : HotelsDotCom
void createParreplacedionedTable(URI sourceTableUri) throws Exception {
    Table hiveTable = TestUtils.createParreplacedionedTable(metaStoreClient, DATABASE, PARreplacedIONED_TABLE, sourceTableUri);
    URI parreplacedionEurope = URI.create(sourceTableUri + "/continent=Europe");
    URI parreplacedionUk = URI.create(parreplacedionEurope + "/country=UK");
    File dataFileUk = new File(parreplacedionUk.getPath(), PART_00000);
    FileUtils.writeStringToFile(dataFileUk, "1\tadam\tlondon\n2\tsusan\tglasgow\n");
    URI parreplacedionAsia = URI.create(sourceTableUri + "/continent=Asia");
    URI parreplacedionChina = URI.create(parreplacedionAsia + "/country=China");
    File dataFileChina = new File(parreplacedionChina.getPath(), PART_00000);
    FileUtils.writeStringToFile(dataFileChina, "1\tchun\tbeijing\n2\tshanghai\tmilan\n");
    LOG.info(">>>> Parreplacedions added: {}", metaStoreClient.add_parreplacedions(Arrays.asList(newTableParreplacedion(hiveTable, Arrays.asList("Europe", "UK"), parreplacedionUk), newTableParreplacedion(hiveTable, Arrays.asList("Asia", "China"), parreplacedionChina))));
}

17 View Complete Implementation : IntegrationTestHelper.java
Copyright Apache License 2.0
Author : HotelsDotCom
void createTableWithEncodedParreplacedion(URI sourceTableUri) throws Exception {
    Table hiveTable = TestUtils.createParreplacedionedTable(metaStoreClient, DATABASE, SOURCE_ENCODED_TABLE, sourceTableUri);
    URI parreplacedionEurope = URI.create(sourceTableUri + "/continent=Europe");
    URI parreplacedionUk = URI.create(parreplacedionEurope + "/country=U%25K");
    File dataFileUk = new File(parreplacedionUk.getPath(), PART_00000);
    FileUtils.writeStringToFile(dataFileUk, "1\tadam\tlondon\n2\tsusan\tglasgow\n");
    LOG.info(">>>> Parreplacedions added: {}", metaStoreClient.add_parreplacedions(Arrays.asList(newTableParreplacedion(hiveTable, Arrays.asList("Europe", "U%K"), URI.create(parreplacedionEurope + "/country=U%25K")))));
}

17 View Complete Implementation : AvroSerDeTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void nullAvroDestinationFailsInTableApply() throws Exception {
    table.putToParameters("avro.schema.url", "/test/");
    Table result = avroSerDeTransformation.apply(table, null, "1");
    replacedertThat(result, is(table));
}

17 View Complete Implementation : HiveEndpoint.java
Copyright Apache License 2.0
Author : HotelsDotCom
/**
 * @return Hive table from the metastore if not found returns {@link Optional#absent()}
 */
public Optional<Table> getTable(CloseableMetaStoreClient client, String database, String table) {
    Table oldReplicaTable = null;
    try {
        log.debug("Checking for existing table {}.{}", database, table);
        oldReplicaTable = client.getTable(database, table);
        log.debug("Existing table found.");
    } catch (NoSuchObjectException e) {
        log.debug("Table '{}.{}' not found.", database, table);
    } catch (TException e) {
        String message = String.format("Cannot fetch table metadata for '%s.%s'", database, table);
        log.error(message, e);
        throw new MetaStoreClientException(message, e);
    }
    return Optional.fromNullable(oldReplicaTable);
}

17 View Complete Implementation : HiveObjectUtilsTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void updateUrlInTable() {
    Table table = newTable();
    table.getParameters().put(AVRO_SCHEMA_URL_PARAMETER, "test");
    table.getSd().getSerdeInfo().getParameters().put(AVRO_SCHEMA_URL_PARAMETER, "test");
    HiveObjectUtils.updateSerDeUrl(table, AVRO_SCHEMA_URL_PARAMETER, "updatedUrl");
    replacedertThat(table.getParameters().get(AVRO_SCHEMA_URL_PARAMETER), is("updatedUrl"));
    replacedertThat(table.getSd().getSerdeInfo().getParameters().get(AVRO_SCHEMA_URL_PARAMETER), is(nullValue()));
}

16 View Complete Implementation : AvroSerDeTableTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void transform() throws Exception {
    EventReplicaTable eventReplicaTable = new EventReplicaTable("db", "table", "location");
    when(tableReplicationEvent.getReplicaTable()).thenReturn(eventReplicaTable);
    HiveObjectUtils.updateSerDeUrl(table, AVRO_SCHEMA_URL_PARAMETER, "avroSourceUrl");
    when(schemaCopier.copy("avroSourceUrl", "schema/eventId/")).thenReturn(destinationPath);
    transformation.tableReplicationStart(tableReplicationEvent, "eventId");
    Table result = transformation.transform(table);
    replacedertThat(result.getParameters().get(AVRO_SCHEMA_URL_PARAMETER), is(destinationPathString));
}

16 View Complete Implementation : ViewTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void underlyingTablesExist() {
    hiveConf.setBoolean(ViewTransformation.SKIP_TABLE_EXIST_CHECKS, false);
    when(table.getTableType()).thenReturn(TableType.VIRTUAL_VIEW.name());
    Table transformedTable = transformation.transform(table);
    replacedertThat(transformedTable, is(not(table)));
    verify(translator).translate(QUALIFIED_NAME, ORIGINAL_HQL);
    verify(translator).translate(QUALIFIED_NAME, EXPANDED_HQL);
    replacedertThat(transformedTable.getViewOriginalText(), is(ORIGINAL_TRANSLATED_HQL));
    replacedertThat(transformedTable.getViewExpandedText(), is(EXPANDED_TRANSLATED_HQL));
}

16 View Complete Implementation : ViewTransformation.java
Copyright Apache License 2.0
Author : HotelsDotCom
private void validateReferencedTables(Table view) {
    TableProcessor processor = new TableProcessor();
    HiveLanguageParser parser = new HiveLanguageParser(new HiveConf());
    parser.parse(view.getViewExpandedText(), processor);
    try (CloseableMetaStoreClient replicaClient = replicaMetaStoreClientSupplier.get()) {
        for (String replicaTable : processor.getTables()) {
            String[] nameParts = MetaStoreUtils.getQualifiedName(null, replicaTable);
            try {
                replicaClient.getTable(nameParts[0], nameParts[1]);
            } catch (NoSuchObjectException e) {
                String message = String.format("Table or view %s does not exists in replica catalog", replicaTable);
                throw new CircusTrainException(message, e);
            } catch (Exception e) {
                String message = String.format("Unable to validate tables used by view %s.%s", view.getDbName(), view.getTableName());
                throw new CircusTrainException(message, e);
            }
        }
    }
}

16 View Complete Implementation : TableParametersTransformationTest.java
Copyright Apache License 2.0
Author : HotelsDotCom
@Test
public void typicalTwoReplicationsBothOverride() {
    transformation.tableReplicationStart(createEventTableReplication(OVERRIDE_KEY, OVERRIDE_VALUE), EVENT_ID);
    transformation.transform(table);
    replacedertThat(table.getParameters().size(), is(1));
    replacedertThat(table.getParameters().get(OVERRIDE_KEY), is(OVERRIDE_VALUE));
    transformation.tableReplicationStart(createEventTableReplication(SECOND_OVERRIDE_KEY, SECOND_OVERRIDE_VALUE), EVENT_ID);
    Table transformedTable = transformation.transform(new Table());
    Map<String, String> tableParameters = transformedTable.getParameters();
    replacedertThat(tableParameters.size(), is(1));
    replacedertThat(tableParameters.get(SECOND_OVERRIDE_KEY), is(SECOND_OVERRIDE_VALUE));
}