/** * This method first tries to obtain the database name from {@link #HIVE_TABLE_NAME}. * If this property is not specified, it then tries to obtain the database name using * the first group of {@link #HIVE_TABLE_REGEX}. */ protected Optional<String> getTableName(Path path) { if (!this.props.contains(HIVE_TABLE_NAME) && !this.props.contains(HIVE_TABLE_REGEX)) { return Optional.<String> absent(); } return Optional.<String> of( this.tableNamePrefix + getDatabaseOrTableName(path, HIVE_TABLE_NAME, HIVE_TABLE_REGEX, this.tableNamePattern) + this.tableNameSuffix); }
/** * This method first tries to obtain the database name from {@link #HIVE_DATABASE_NAME}. * If this property is not specified, it then tries to obtain the database name using * the first group of {@link #HIVE_DATABASE_REGEX}. * */ protected Optional<String> getDatabaseName(Path path) { if (!this.props.contains(HIVE_DATABASE_NAME) && !this.props.contains(HIVE_DATABASE_REGEX)) { return Optional.<String> absent(); } return Optional.<String> of( this.dbNamePrefix + getDatabaseOrTableName(path, HIVE_DATABASE_NAME, HIVE_DATABASE_REGEX, this.dbNamePattern) + this.dbNameSuffix); }
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); }
/** * Create a {@link State} object that contains Hive table properties. These properties are obtained from * {@link #HIVE_TABLE_PARTITION_PROPS}, which is a list of comma-separated properties. Each property is in the form * of '[key]=[value]'. */ private State createHiveProps(String propKey) { State state = new State(); if (!contains(propKey)) { return state; } for (String propValue : getPropAsList(propKey)) { List<String> tokens = SPLITTER.splitToList(propValue); Preconditions.checkState(tokens.size() == 2, propValue + " is not a valid Hive table/partition property"); state.setProp(tokens.get(0), tokens.get(1)); } return state; }
/** * This method first tries to obtain the database name from {@link #HIVE_TABLE_NAME}. * If this property is not specified, it then tries to obtain the database name using * the first group of {@link #HIVE_TABLE_REGEX}. */ protected Optional<String> getTableName(Path path) { if (!this.props.contains(HIVE_TABLE_NAME) && !this.props.contains(HIVE_TABLE_REGEX)) { return Optional.<String> absent(); } return Optional.<String> of( this.tableNamePrefix + getDatabaseOrTableName(path, HIVE_TABLE_NAME, HIVE_TABLE_REGEX, this.tableNamePattern) + this.tableNameSuffix); }
/** * This method first tries to obtain the database name from {@link #HIVE_DATABASE_NAME}. * If this property is not specified, it then tries to obtain the database name using * the first group of {@link #HIVE_DATABASE_REGEX}. * */ protected Optional<String> getDatabaseName(Path path) { if (!this.props.contains(HIVE_DATABASE_NAME) && !this.props.contains(HIVE_DATABASE_REGEX)) { return Optional.<String> absent(); } return Optional.<String> of( this.dbNamePrefix + getDatabaseOrTableName(path, HIVE_DATABASE_NAME, HIVE_DATABASE_REGEX, this.dbNamePattern) + this.dbNameSuffix); }
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); }
/** * Create a {@link State} object that contains Hive table properties. These properties are obtained from * {@link #HIVE_TABLE_PARTITION_PROPS}, which is a list of comma-separated properties. Each property is in the form * of '[key]=[value]'. */ private State createHiveProps(String propKey) { State state = new State(); if (!contains(propKey)) { return state; } for (String propValue : getPropAsList(propKey)) { List<String> tokens = SPLITTER.splitToList(propValue); Preconditions.checkState(tokens.size() == 2, propValue + " is not a valid Hive table/partition property"); state.setProp(tokens.get(0), tokens.get(1)); } return state; }