@Test public void testExtractTokenValueFromEntity() throws IOException { String tokenValue; tokenValue = HiveDataset.extractTokenValueFromEntity("dbPrefix_myDB_dbPostfix", "dbPrefix_$LOGICAL_DB_dbPostfix", HiveDataset.LOGICAL_DB_TOKEN); Assert.assertEquals(tokenValue, "myDB", "DB name not extracted correctly"); tokenValue = HiveDataset.extractTokenValueFromEntity("myDB_dbPostfix", "$LOGICAL_DB_dbPostfix", HiveDataset.LOGICAL_DB_TOKEN); Assert.assertEquals(tokenValue, "myDB", "DB name not extracted correctly"); tokenValue = HiveDataset.extractTokenValueFromEntity("dbPrefix_myDB", "dbPrefix_$LOGICAL_DB", HiveDataset.LOGICAL_DB_TOKEN); Assert.assertEquals(tokenValue, "myDB", "DB name not extracted correctly"); try { tokenValue = HiveDataset.extractTokenValueFromEntity("dbPrefix_myDB_dbPostfix", "dbPrefix_$LOGICAL_TABLE_dbPostfix", HiveDataset.LOGICAL_DB_TOKEN); Assert.fail("Token is missing in template, code should have thrown exception"); } catch (IllegalArgumentException e) { } try { tokenValue = HiveDataset.extractTokenValueFromEntity("", "dbPrefix_$LOGICAL_DB_dbPostfix", HiveDataset.LOGICAL_DB_TOKEN); Assert.fail("Source entity is missing, code should have thrown exception"); } catch (IllegalArgumentException e) { } try { tokenValue = HiveDataset.extractTokenValueFromEntity("dbPrefix_myDB_dbPostfix", "", HiveDataset.LOGICAL_DB_TOKEN); Assert.fail("Template is missing, code should have thrown exception"); } catch (IllegalArgumentException e) { } }
@VisibleForTesting protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) { Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank"); Preconditions.checkArgument(sourceTemplate.contains(token), String.format("Source template: %s should contain token: %s", sourceTemplate, token)); String extractedValue = sourceEntity; List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate)); extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0)); extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1)); return extractedValue; }
HiveDataset implements PrioritizedCopyableDataset { @VisibleForTesting protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) { Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank"); Preconditions.checkArgument(sourceTemplate.contains(token), String.format("Source template: %s should contain token: %s", sourceTemplate, token)); String extractedValue = sourceEntity; List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate)); extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0)); extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1)); return extractedValue; } }
HiveDataset implements PrioritizedCopyableDataset { @VisibleForTesting protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) { Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank"); Preconditions.checkArgument(sourceTemplate.contains(token), String.format("Source template: %s should contain token: %s", sourceTemplate, token)); String extractedValue = sourceEntity; List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate)); extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0)); extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1)); return extractedValue; } HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Properties properties);  HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Config datasetConfig);  HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Properties properties, Config datasetConfig); }
HiveDataset implements PrioritizedCopyableDataset { @VisibleForTesting protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) { Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank"); Preconditions.checkArgument(sourceTemplate.contains(token), String.format("Source template: %s should contain token: %s", sourceTemplate, token)); String extractedValue = sourceEntity; List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate)); extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0)); extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1)); return extractedValue; } HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Properties properties);  HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Config datasetConfig);  HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Properties properties, Config datasetConfig); @Override Iterator<FileSet<CopyEntity>> getFileSetIterator(FileSystem targetFs, CopyConfiguration configuration); @Override Iterator<FileSet<CopyEntity>> getFileSetIterator(FileSystem targetFs, CopyConfiguration configuration,
      Comparator<FileSet<CopyEntity>> prioritizer, PushDownRequestor<FileSet<CopyEntity>> requestor); @Override String datasetURN(); static String resolveTemplate(String rawString, Table table); static List<Partition> sortPartitions(List<Partition> partitions); List<Partition> getPartitionsFromDataset(); }
HiveDataset implements PrioritizedCopyableDataset { @VisibleForTesting protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) { Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank"); Preconditions.checkArgument(sourceTemplate.contains(token), String.format("Source template: %s should contain token: %s", sourceTemplate, token)); String extractedValue = sourceEntity; List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate)); extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0)); extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1)); return extractedValue; } HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Properties properties);  HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Config datasetConfig);  HiveDataset(FileSystem fs, HiveMetastoreClientPool clientPool, Table table, Properties properties, Config datasetConfig); @Override Iterator<FileSet<CopyEntity>> getFileSetIterator(FileSystem targetFs, CopyConfiguration configuration); @Override Iterator<FileSet<CopyEntity>> getFileSetIterator(FileSystem targetFs, CopyConfiguration configuration,
      Comparator<FileSet<CopyEntity>> prioritizer, PushDownRequestor<FileSet<CopyEntity>> requestor); @Override String datasetURN(); static String resolveTemplate(String rawString, Table table); static List<Partition> sortPartitions(List<Partition> partitions); List<Partition> getPartitionsFromDataset(); static final ImmutableSet<TableType> COPYABLE_TABLES; static final String REGISTERER; static final String REGISTRATION_GENERATION_TIME_MILLIS; static final String DATASET_NAME_PATTERN_KEY; static final String DATABASE; static final String TABLE; static final String DATASET_STAGING_PATH; static final String DATABASE_TOKEN; static final String TABLE_TOKEN; static final String LOGICAL_DB_TOKEN; static final String LOGICAL_TABLE_TOKEN; }