@Test public void testValidateRetentionConfig() { Schema schema = new Schema.SchemaBuilder().setSchemaName(TABLE_NAME).addSingleValueDimension("myCol", FieldSpec.DataType.STRING) .build(); TableConfig tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME).setRetentionTimeUnit("hours") .setRetentionTimeValue("24").build(); try { TableConfigUtils.validate(tableConfig, schema); } catch (Exception e) { Assert.fail("Should not fail for valid retention time unit value"); } tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME).setRetentionTimeUnit("abc").build(); try { TableConfigUtils.validate(tableConfig, schema); Assert.fail("Should fail for invalid retention time unit value"); } catch (Exception e) { } }
public static void validateRetentionConfig(TableConfig tableConfig) { SegmentsValidationAndRetentionConfig segmentsConfig = tableConfig.getValidationConfig(); String tableName = tableConfig.getTableName(); if (segmentsConfig == null) { throw new IllegalStateException( String.format("Table: %s, \"segmentsConfig\" field is missing in table config", tableName)); } String segmentPushType = segmentsConfig.getSegmentPushType(); if (tableConfig.getTableType() == TableType.OFFLINE && segmentPushType != null && !segmentPushType.isEmpty()) { if (!segmentPushType.equalsIgnoreCase("REFRESH") && !segmentPushType.equalsIgnoreCase("APPEND")) { throw new IllegalStateException(String.format("Table: %s, invalid push type: %s", tableName, segmentPushType)); } } String timeUnitString = segmentsConfig.getRetentionTimeUnit(); if (timeUnitString == null || timeUnitString.isEmpty()) { return; } try { TimeUnit.valueOf(timeUnitString.toUpperCase()); } catch (Exception e) { throw new IllegalStateException(String.format("Table: %s, invalid time unit: %s", tableName, timeUnitString)); } }
TableConfigUtils { public static void validateRetentionConfig(TableConfig tableConfig) { SegmentsValidationAndRetentionConfig segmentsConfig = tableConfig.getValidationConfig(); String tableName = tableConfig.getTableName(); if (segmentsConfig == null) { throw new IllegalStateException( String.format("Table: %s, \"segmentsConfig\" field is missing in table config", tableName)); } String segmentPushType = segmentsConfig.getSegmentPushType(); if (tableConfig.getTableType() == TableType.OFFLINE && segmentPushType != null && !segmentPushType.isEmpty()) { if (!segmentPushType.equalsIgnoreCase("REFRESH") && !segmentPushType.equalsIgnoreCase("APPEND")) { throw new IllegalStateException(String.format("Table: %s, invalid push type: %s", tableName, segmentPushType)); } } String timeUnitString = segmentsConfig.getRetentionTimeUnit(); if (timeUnitString == null || timeUnitString.isEmpty()) { return; } try { TimeUnit.valueOf(timeUnitString.toUpperCase()); } catch (Exception e) { throw new IllegalStateException(String.format("Table: %s, invalid time unit: %s", tableName, timeUnitString)); } } }
TableConfigUtils { public static void validateRetentionConfig(TableConfig tableConfig) { SegmentsValidationAndRetentionConfig segmentsConfig = tableConfig.getValidationConfig(); String tableName = tableConfig.getTableName(); if (segmentsConfig == null) { throw new IllegalStateException( String.format("Table: %s, \"segmentsConfig\" field is missing in table config", tableName)); } String segmentPushType = segmentsConfig.getSegmentPushType(); if (tableConfig.getTableType() == TableType.OFFLINE && segmentPushType != null && !segmentPushType.isEmpty()) { if (!segmentPushType.equalsIgnoreCase("REFRESH") && !segmentPushType.equalsIgnoreCase("APPEND")) { throw new IllegalStateException(String.format("Table: %s, invalid push type: %s", tableName, segmentPushType)); } } String timeUnitString = segmentsConfig.getRetentionTimeUnit(); if (timeUnitString == null || timeUnitString.isEmpty()) { return; } try { TimeUnit.valueOf(timeUnitString.toUpperCase()); } catch (Exception e) { throw new IllegalStateException(String.format("Table: %s, invalid time unit: %s", tableName, timeUnitString)); } } private  TableConfigUtils(); }
TableConfigUtils { public static void validateRetentionConfig(TableConfig tableConfig) { SegmentsValidationAndRetentionConfig segmentsConfig = tableConfig.getValidationConfig(); String tableName = tableConfig.getTableName(); if (segmentsConfig == null) { throw new IllegalStateException( String.format("Table: %s, \"segmentsConfig\" field is missing in table config", tableName)); } String segmentPushType = segmentsConfig.getSegmentPushType(); if (tableConfig.getTableType() == TableType.OFFLINE && segmentPushType != null && !segmentPushType.isEmpty()) { if (!segmentPushType.equalsIgnoreCase("REFRESH") && !segmentPushType.equalsIgnoreCase("APPEND")) { throw new IllegalStateException(String.format("Table: %s, invalid push type: %s", tableName, segmentPushType)); } } String timeUnitString = segmentsConfig.getRetentionTimeUnit(); if (timeUnitString == null || timeUnitString.isEmpty()) { return; } try { TimeUnit.valueOf(timeUnitString.toUpperCase()); } catch (Exception e) { throw new IllegalStateException(String.format("Table: %s, invalid time unit: %s", tableName, timeUnitString)); } } private  TableConfigUtils(); static void validate(TableConfig tableConfig, @Nullable Schema schema); static void validateTableName(TableConfig tableConfig); static void validateRetentionConfig(TableConfig tableConfig); }
TableConfigUtils { public static void validateRetentionConfig(TableConfig tableConfig) { SegmentsValidationAndRetentionConfig segmentsConfig = tableConfig.getValidationConfig(); String tableName = tableConfig.getTableName(); if (segmentsConfig == null) { throw new IllegalStateException( String.format("Table: %s, \"segmentsConfig\" field is missing in table config", tableName)); } String segmentPushType = segmentsConfig.getSegmentPushType(); if (tableConfig.getTableType() == TableType.OFFLINE && segmentPushType != null && !segmentPushType.isEmpty()) { if (!segmentPushType.equalsIgnoreCase("REFRESH") && !segmentPushType.equalsIgnoreCase("APPEND")) { throw new IllegalStateException(String.format("Table: %s, invalid push type: %s", tableName, segmentPushType)); } } String timeUnitString = segmentsConfig.getRetentionTimeUnit(); if (timeUnitString == null || timeUnitString.isEmpty()) { return; } try { TimeUnit.valueOf(timeUnitString.toUpperCase()); } catch (Exception e) { throw new IllegalStateException(String.format("Table: %s, invalid time unit: %s", tableName, timeUnitString)); } } private  TableConfigUtils(); static void validate(TableConfig tableConfig, @Nullable Schema schema); static void validateTableName(TableConfig tableConfig); static void validateRetentionConfig(TableConfig tableConfig);  }