@Test(expectedExceptions = IllegalStateException.class) public void testTableRegexpWithoutMatchShouldFail() throws IOException { State state = new State(); String regexp = "^hdfs: Optional<Pattern> pattern = Optional.of(Pattern.compile(regexp)); Path path = new Path("s3: state.appendToListProp(HiveRegistrationPolicyBase.HIVE_DATABASE_REGEX, regexp); HiveRegistrationPolicyBase registrationPolicyBase = new HiveRegistrationPolicyBase(state); String resultTable = registrationPolicyBase.getDatabaseOrTableName(path, HiveRegistrationPolicyBase.HIVE_DATABASE_NAME, HiveRegistrationPolicyBase.HIVE_DATABASE_REGEX, pattern ); Assert.assertEquals(resultTable, "topic"); }
protected String getDatabaseOrTableName(Path path, String nameKey, String regexKey, Optional<Pattern> pattern) { String name; if (this.props.contains(nameKey)) { name = this.props.getProp(nameKey); } else if (pattern.isPresent()) { Matcher matcher = pattern.get().matcher(path.toString()); if (matcher.matches() && matcher.groupCount() >= 1) { name = matcher.group(1); } else { throw new IllegalStateException("No group match found for regexKey " + regexKey+" with regexp "+ pattern.get().toString() +" on path "+path); } } else { throw new IllegalStateException("Missing required property " + nameKey + " or " + regexKey); } return sanitizeAndValidateName(name); }
HiveRegistrationPolicyBase implements HiveRegistrationPolicy { protected String getDatabaseOrTableName(Path path, String nameKey, String regexKey, Optional<Pattern> pattern) { String name; if (this.props.contains(nameKey)) { name = this.props.getProp(nameKey); } else if (pattern.isPresent()) { Matcher matcher = pattern.get().matcher(path.toString()); if (matcher.matches() && matcher.groupCount() >= 1) { name = matcher.group(1); } else { throw new IllegalStateException("No group match found for regexKey " + regexKey+" with regexp "+ pattern.get().toString() +" on path "+path); } } else { throw new IllegalStateException("Missing required property " + nameKey + " or " + regexKey); } return sanitizeAndValidateName(name); } }
HiveRegistrationPolicyBase implements HiveRegistrationPolicy { protected String getDatabaseOrTableName(Path path, String nameKey, String regexKey, Optional<Pattern> pattern) { String name; if (this.props.contains(nameKey)) { name = this.props.getProp(nameKey); } else if (pattern.isPresent()) { Matcher matcher = pattern.get().matcher(path.toString()); if (matcher.matches() && matcher.groupCount() >= 1) { name = matcher.group(1); } else { throw new IllegalStateException("No group match found for regexKey " + regexKey+" with regexp "+ pattern.get().toString() +" on path "+path); } } else { throw new IllegalStateException("Missing required property " + nameKey + " or " + regexKey); } return sanitizeAndValidateName(name); } HiveRegistrationPolicyBase(State props); }
HiveRegistrationPolicyBase implements HiveRegistrationPolicy { protected String getDatabaseOrTableName(Path path, String nameKey, String regexKey, Optional<Pattern> pattern) { String name; if (this.props.contains(nameKey)) { name = this.props.getProp(nameKey); } else if (pattern.isPresent()) { Matcher matcher = pattern.get().matcher(path.toString()); if (matcher.matches() && matcher.groupCount() >= 1) { name = matcher.group(1); } else { throw new IllegalStateException("No group match found for regexKey " + regexKey+" with regexp "+ pattern.get().toString() +" on path "+path); } } else { throw new IllegalStateException("Missing required property " + nameKey + " or " + regexKey); } return sanitizeAndValidateName(name); } HiveRegistrationPolicyBase(State props); @Override Collection<HiveSpec> getHiveSpecs(Path path); static HiveRegistrationPolicy getPolicy(State props); }
HiveRegistrationPolicyBase implements HiveRegistrationPolicy { protected String getDatabaseOrTableName(Path path, String nameKey, String regexKey, Optional<Pattern> pattern) { String name; if (this.props.contains(nameKey)) { name = this.props.getProp(nameKey); } else if (pattern.isPresent()) { Matcher matcher = pattern.get().matcher(path.toString()); if (matcher.matches() && matcher.groupCount() >= 1) { name = matcher.group(1); } else { throw new IllegalStateException("No group match found for regexKey " + regexKey+" with regexp "+ pattern.get().toString() +" on path "+path); } } else { throw new IllegalStateException("Missing required property " + nameKey + " or " + regexKey); } return sanitizeAndValidateName(name); } HiveRegistrationPolicyBase(State props); @Override Collection<HiveSpec> getHiveSpecs(Path path); static HiveRegistrationPolicy getPolicy(State props); static final String HIVE_DATABASE_NAME; static final String ADDITIONAL_HIVE_DATABASE_NAMES; static final String HIVE_DATABASE_REGEX; static final String HIVE_DATABASE_NAME_PREFIX; static final String HIVE_DATABASE_NAME_SUFFIX; static final String HIVE_TABLE_NAME; static final String ADDITIONAL_HIVE_TABLE_NAMES; static final String HIVE_TABLE_REGEX; static final String HIVE_TABLE_NAME_PREFIX; static final String HIVE_TABLE_NAME_SUFFIX; static final String HIVE_SANITIZE_INVALID_NAMES; static final String HIVE_FS_URI; static final String PRIMARY_TABLE_TOKEN; static final String CONFIG_FOR_TOPIC_TIMER; }