@SuppressWarnings("serial") @Override protected void populateTablePartitionFields(State state) { super.populateTablePartitionFields(state); this.owner = populateField(state, HiveConstants.OWNER, new TypeToken<String>() {}); this.tableType = populateField(state, HiveConstants.TABLE_TYPE, new TypeToken<String>() {}); this.retention = populateField(state, HiveConstants.RETENTION, new TypeToken<Long>() {}); }
@SuppressWarnings("unchecked") public T compareIsCompressed() { if (!this.result) { compare(this.existingUnit.getIsCompressed(), this.newUnit.getIsCompressed()); } return (T) this; }
@SuppressWarnings("unchecked") public T compareBucketCols() { if (!this.result) { compare(this.existingUnit.getBucketColumns(), this.newUnit.getBucketColumns()); } return (T) this; }
/** * Compare all parameters. */ @SuppressWarnings("unchecked") public T compareAll() { this.compareInputFormat().compareOutputFormat().compareIsCompressed().compareIsStoredAsSubDirs().compareNumBuckets() .compareBucketCols().compareRawLocation().compareParameters(); return (T) this; }
@SuppressWarnings("unchecked") public T compareParameters() { if (!this.result) { checkExistingIsSuperstate(this.existingUnit.getProps(), this.newUnit.getProps()); checkExistingIsSuperstate(this.existingUnit.getStorageProps(), this.newUnit.getStorageProps()); checkExistingIsSuperstate(this.existingUnit.getSerDeProps(), this.newUnit.getSerDeProps()); } return (T) this; }
@SuppressWarnings("unchecked") @Override public T compareAll() { super.compareAll().compareOwner().compareRetention(); return (T) this; } }
protected boolean needToUpdatePartition(HivePartition existingPartition, HivePartition newPartition) { return getPartitionComparator(existingPartition, newPartition).compareAll().result(); }
protected boolean needToUpdateTable(HiveTable existingTable, HiveTable newTable) { return getTableComparator(existingTable, newTable).compareAll().result(); }
@SuppressWarnings("unchecked") public T compareRetention() { if (!this.result) { compare(((HiveTable) this.existingUnit).getRetention(), ((HiveTable) this.newUnit).getRetention()); } return (T) this; }
@SuppressWarnings("unchecked") @Override public T compareAll() { super.compareAll().compareValues(); return (T) this; }
@SuppressWarnings("unchecked") public T compareInputFormat() { if (!this.result) { compare(this.existingUnit.getInputFormat(), this.newUnit.getInputFormat()); } return (T) this; }
@SuppressWarnings("unchecked") public T compareNumBuckets() { if (!this.result) { compare(this.existingUnit.getNumBuckets(), this.newUnit.getNumBuckets()); } return (T) this; }
@SuppressWarnings("unchecked") public T compareOutputFormat() { if (!this.result) { compare(this.existingUnit.getOutputFormat(), this.newUnit.getOutputFormat()); } return (T) this; }
@SuppressWarnings("unchecked") public T compareIsStoredAsSubDirs() { if (!this.result) { compare(this.existingUnit.getIsStoredAsSubDirs(), this.newUnit.getIsStoredAsSubDirs()); } return (T) this; }
/** * Add a partition to a table if not exists, or alter a partition if exists. * * @param table the {@link HiveTable} to which the partition belongs. * @param partition a {@link HivePartition} to which the existing partition should be updated. * @throws IOException */ public void addOrAlterPartition(HiveTable table, HivePartition partition) throws IOException { if (!addPartitionIfNotExists(table, partition)) { alterPartition(table, partition); } }
@Override public boolean execute(HiveRegister register) throws IOException { register.dropTableIfExists(this.dbName, this.tableName); return true; }
@SuppressWarnings({ "serial" }) protected void populateStorageFields(State state) { this.location = populateField(state, HiveConstants.LOCATION, new TypeToken<String>() {}); this.inputFormat = populateField(state, HiveConstants.INPUT_FORMAT, new TypeToken<String>() {}); this.outputFormat = populateField(state, HiveConstants.OUTPUT_FORMAT, new TypeToken<String>() {}); this.isCompressed = populateField(state, HiveConstants.COMPRESSED, new TypeToken<Boolean>() {}); this.numBuckets = populateField(state, HiveConstants.NUM_BUCKETS, new TypeToken<Integer>() {}); this.bucketColumns = populateField(state, HiveConstants.BUCKET_COLUMNS, new TypeToken<List<String>>() {}); this.isStoredAsSubDirs = populateField(state, HiveConstants.STORED_AS_SUB_DIRS, new TypeToken<Boolean>() {}); }
@Override public boolean execute(HiveRegister register) throws IOException { register.dropPartitionIfExists(this.dbName, this.tableName, this.partitionKeys, this.partitionValues); return true; }
@Override public HiveTable build() { return new HiveTable(this); } }