Java Code Examples for org.apache.flink.util.TimeUtils#parseDuration()

The following examples show how to use org.apache.flink.util.TimeUtils#parseDuration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
private static Duration getConfiguredIntervalOrDefault(ReporterSetup reporterSetup) {
	final Optional<String> configuredPeriod = reporterSetup.getIntervalSettings();
	Duration period = MetricOptions.REPORTER_INTERVAL.defaultValue();

	if (configuredPeriod.isPresent()) {
		try {
			period = TimeUtils.parseDuration(configuredPeriod.get());
		}
		catch (Exception e) {
			LOG.error("Cannot parse report interval from config: " + configuredPeriod +
				" - please use values like '10 SECONDS' or '500 MILLISECONDS'. " +
				"Using default reporting interval.");
		}
	}
	return period;
}
 
Example 2
Source File: Configuration.java    From flink with Apache License 2.0 5 votes vote down vote up
private Duration convertToDuration(Object o) {
	if (o.getClass() == Duration.class) {
		return (Duration) o;
	}

	return TimeUtils.parseDuration(o.toString());
}
 
Example 3
Source File: HiveTableSource.java    From flink with Apache License 2.0 4 votes vote down vote up
private List<HiveTablePartition> initAllPartitions() {
	List<HiveTablePartition> allHivePartitions = new ArrayList<>();
	// Please note that the following directly accesses Hive metastore, which is only a temporary workaround.
	// Ideally, we need to go thru Catalog API to get all info we need here, which requires some major
	// refactoring. We will postpone this until we merge Blink to Flink.
	try (HiveMetastoreClientWrapper client = HiveMetastoreClientFactory.create(new HiveConf(jobConf, HiveConf.class), hiveVersion)) {
		String dbName = tablePath.getDatabaseName();
		String tableName = tablePath.getObjectName();
		List<String> partitionColNames = catalogTable.getPartitionKeys();
		Table hiveTable = client.getTable(dbName, tableName);
		Properties tableProps = HiveReflectionUtils.getTableMetadata(hiveShim, hiveTable);
		String ttlStr = tableProps.getProperty(FileSystemOptions.LOOKUP_JOIN_CACHE_TTL.key());
		hiveTableCacheTTL = ttlStr != null ?
				TimeUtils.parseDuration(ttlStr) :
				FileSystemOptions.LOOKUP_JOIN_CACHE_TTL.defaultValue();
		if (partitionColNames != null && partitionColNames.size() > 0) {
			final String defaultPartitionName = jobConf.get(HiveConf.ConfVars.DEFAULTPARTITIONNAME.varname,
					HiveConf.ConfVars.DEFAULTPARTITIONNAME.defaultStrVal);
			List<Partition> partitions = new ArrayList<>();
			if (remainingPartitions != null) {
				for (Map<String, String> spec : remainingPartitions) {
					partitions.add(client.getPartition(dbName, tableName, partitionSpecToValues(spec, partitionColNames)));
				}
			} else {
				partitions.addAll(client.listPartitions(dbName, tableName, (short) -1));
			}
			for (Partition partition : partitions) {
				HiveTablePartition hiveTablePartition = toHiveTablePartition(
						catalogTable.getPartitionKeys(),
						catalogTable.getSchema().getFieldNames(),
						catalogTable.getSchema().getFieldDataTypes(),
						hiveShim,
						tableProps,
						defaultPartitionName,
						partition);
				allHivePartitions.add(hiveTablePartition);
			}
		} else {
			allHivePartitions.add(new HiveTablePartition(hiveTable.getSd(), tableProps));
		}
	} catch (TException e) {
		throw new FlinkHiveException("Failed to collect all partitions from hive metaStore", e);
	}
	return allHivePartitions;
}