本文整理匯總了Java中org.apache.flink.api.java.tuple.Tuple2.of方法的典型用法代碼示例。如果您正苦於以下問題:Java Tuple2.of方法的具體用法?Java Tuple2.of怎麽用?Java Tuple2.of使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.flink.api.java.tuple.Tuple2
的用法示例。
在下文中一共展示了Tuple2.of方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: map
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
@Override
public Tuple2<Integer, Boolean> map(TaxiRide taxiRide) throws Exception {
float lon;
float lat;
final boolean isStart = taxiRide.isStart;
if(isStart) {
lon = taxiRide.startLon;
lat = taxiRide.startLat;
}
else {
lon = taxiRide.endLon;
lat = taxiRide.endLat;
}
int gridId = GeoUtils.mapToGridCell(lon, lat);
return Tuple2.of(gridId, isStart);
}
示例2: getOffsetAndLengthForSplit
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
private Tuple2<Long, Long> getOffsetAndLengthForSplit(FileInputSplit split, List<StripeInformation> stripes) {
long splitStart = split.getStart();
long splitEnd = splitStart + split.getLength();
long readStart = Long.MAX_VALUE;
long readEnd = Long.MIN_VALUE;
for (StripeInformation s : stripes) {
if (splitStart <= s.getOffset() && s.getOffset() < splitEnd) {
// stripe starts in split, so it is included
readStart = Math.min(readStart, s.getOffset());
readEnd = Math.max(readEnd, s.getOffset() + s.getLength());
}
}
if (readStart < Long.MAX_VALUE) {
// at least one split is included
return Tuple2.of(readStart, readEnd - readStart);
} else {
return Tuple2.of(0L, 0L);
}
}
示例3: getJobManagerAddress
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
/**
* Returns the JobManager's hostname and port extracted from the given
* {@link Configuration}.
*
* @param configuration Configuration to extract the JobManager's address from
* @return The JobManager's hostname and port
* @throws ConfigurationException if the JobManager's address cannot be extracted from the configuration
*/
public static Tuple2<String, Integer> getJobManagerAddress(Configuration configuration) throws ConfigurationException {
final String hostname = configuration.getString(JobManagerOptions.ADDRESS);
final int port = configuration.getInteger(JobManagerOptions.PORT);
if (hostname == null) {
throw new ConfigurationException("Config parameter '" + JobManagerOptions.ADDRESS +
"' is missing (hostname/address of JobManager to connect to).");
}
if (port <= 0 || port >= 65536) {
throw new ConfigurationException("Invalid value for '" + JobManagerOptions.PORT +
"' (port of the JobManager actor system) : " + port +
". it must be greater than 0 and less than 65536.");
}
return Tuple2.of(hostname, port);
}
示例4: getJobGraphAndClassLoader
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
protected Tuple2<JobGraph, ClassLoader> getJobGraphAndClassLoader(JarActionHandlerConfig config) throws Exception {
// generate the graph
JobGraph graph = null;
PackagedProgram program = new PackagedProgram(
new File(jarDir, config.getJarFile()),
config.getEntryClass(),
config.getProgramArgs());
ClassLoader classLoader = program.getUserCodeClassLoader();
Optimizer optimizer = new Optimizer(new DataStatistics(), new DefaultCostEstimator(), new Configuration());
FlinkPlan plan = ClusterClient.getOptimizedPlan(optimizer, program, config.getParallelism());
if (plan instanceof StreamingPlan) {
graph = ((StreamingPlan) plan).getJobGraph();
} else if (plan instanceof OptimizedPlan) {
graph = new JobGraphGenerator().compileJobGraph((OptimizedPlan) plan);
}
if (graph == null) {
throw new CompilerException("A valid job graph couldn't be generated for the jar.");
}
// Set the savepoint settings
graph.setSavepointRestoreSettings(config.getSavepointRestoreSettings());
for (URL jar : program.getAllLibraries()) {
try {
graph.addJar(new Path(jar.toURI()));
}
catch (URISyntaxException e) {
throw new ProgramInvocationException("Invalid jar path. Unexpected error. :(");
}
}
return Tuple2.of(graph, classLoader);
}
示例5: setupLocalResource
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
/**
* Copy a local file to a remote file system.
*
* @param fs
* remote filesystem
* @param appId
* application ID
* @param localSrcPath
* path to the local file
* @param homedir
* remote home directory base (will be extended)
* @param relativeTargetPath
* relative target path of the file (will be prefixed be the full home directory we set up)
*
* @return Path to remote file (usually hdfs)
*/
static Tuple2<Path, LocalResource> setupLocalResource(
FileSystem fs,
String appId,
Path localSrcPath,
Path homedir,
String relativeTargetPath) throws IOException {
if (new File(localSrcPath.toUri().getPath()).isDirectory()) {
throw new IllegalArgumentException("File to copy must not be a directory: " +
localSrcPath);
}
// copy resource to HDFS
String suffix =
".flink/"
+ appId
+ (relativeTargetPath.isEmpty() ? "" : "/" + relativeTargetPath)
+ "/" + localSrcPath.getName();
Path dst = new Path(homedir, suffix);
LOG.info("Copying from " + localSrcPath + " to " + dst);
fs.copyFromLocalFile(false, true, localSrcPath, dst);
// now create the resource instance
LocalResource resource = registerLocalResource(fs, dst);
return Tuple2.of(dst, resource);
}
示例6: extractAddressHostname
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
private Tuple2<String, String> extractAddressHostname(ActorRef actorRef) {
final String actorAddress = AkkaUtils.getAkkaURL(actorSystem, actorRef);
final String hostname;
Option<String> host = actorRef.path().address().host();
if (host.isEmpty()) {
hostname = "localhost";
} else {
hostname = host.get();
}
return Tuple2.of(actorAddress, hostname);
}
示例7: testIllegalFlatTuple
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
@Test(expected = CompositeType.InvalidFieldReferenceException.class)
public void testIllegalFlatTuple() {
Tuple2<String, Integer> t = Tuple2.of("aa", 5);
TupleTypeInfo<Tuple2<String, Integer>> tpeInfo =
(TupleTypeInfo<Tuple2<String, Integer>>) TypeExtractor.getForObject(t);
FieldAccessorFactory.getAccessor(tpeInfo, "illegal", null);
}
示例8: filterArguments
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
/**
* Removes all {@link RpcTimeout} annotated parameters from the parameter type and argument
* list.
*
* @param parameterTypes Array of parameter types
* @param parameterAnnotations Array of parameter annotations
* @param args Arary of arguments
* @return Tuple of filtered parameter types and arguments which no longer contain the
* {@link RpcTimeout} annotated parameter types and arguments
*/
private static Tuple2<Class<?>[], Object[]> filterArguments(
Class<?>[] parameterTypes,
Annotation[][] parameterAnnotations,
Object[] args) {
Class<?>[] filteredParameterTypes;
Object[] filteredArgs;
if (args == null) {
filteredParameterTypes = parameterTypes;
filteredArgs = null;
} else {
Preconditions.checkArgument(parameterTypes.length == parameterAnnotations.length);
Preconditions.checkArgument(parameterAnnotations.length == args.length);
BitSet isRpcTimeoutParameter = new BitSet(parameterTypes.length);
int numberRpcParameters = parameterTypes.length;
for (int i = 0; i < parameterTypes.length; i++) {
if (isRpcTimeout(parameterAnnotations[i])) {
isRpcTimeoutParameter.set(i);
numberRpcParameters--;
}
}
if (numberRpcParameters == parameterTypes.length) {
filteredParameterTypes = parameterTypes;
filteredArgs = args;
} else {
filteredParameterTypes = new Class<?>[numberRpcParameters];
filteredArgs = new Object[numberRpcParameters];
int counter = 0;
for (int i = 0; i < parameterTypes.length; i++) {
if (!isRpcTimeoutParameter.get(i)) {
filteredParameterTypes[counter] = parameterTypes[i];
filteredArgs[counter] = args[i];
counter++;
}
}
}
}
return Tuple2.of(filteredParameterTypes, filteredArgs);
}
示例9: testFlatTuple
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
@Test
public void testFlatTuple() {
Tuple2<String, Integer> t = Tuple2.of("aa", 5);
TupleTypeInfo<Tuple2<String, Integer>> tpeInfo =
(TupleTypeInfo<Tuple2<String, Integer>>) TypeExtractor.getForObject(t);
FieldAccessor<Tuple2<String, Integer>, String> f0 = FieldAccessorFactory.getAccessor(tpeInfo, "f0", null);
assertEquals("aa", f0.get(t));
assertEquals("aa", t.f0);
t = f0.set(t, "b");
assertEquals("b", f0.get(t));
assertEquals("b", t.f0);
FieldAccessor<Tuple2<String, Integer>, Integer> f1 = FieldAccessorFactory.getAccessor(tpeInfo, "f1", null);
assertEquals(5, (int) f1.get(t));
assertEquals(5, (int) t.f1);
t = f1.set(t, 7);
assertEquals(7, (int) f1.get(t));
assertEquals(7, (int) t.f1);
assertEquals("b", f0.get(t));
assertEquals("b", t.f0);
FieldAccessor<Tuple2<String, Integer>, Integer> f1n = FieldAccessorFactory.getAccessor(tpeInfo, 1, null);
assertEquals(7, (int) f1n.get(t));
assertEquals(7, (int) t.f1);
t = f1n.set(t, 10);
assertEquals(10, (int) f1n.get(t));
assertEquals(10, (int) f1.get(t));
assertEquals(10, (int) t.f1);
assertEquals("b", f0.get(t));
assertEquals("b", t.f0);
FieldAccessor<Tuple2<String, Integer>, Integer> f1ns = FieldAccessorFactory.getAccessor(tpeInfo, "1", null);
assertEquals(10, (int) f1ns.get(t));
assertEquals(10, (int) t.f1);
t = f1ns.set(t, 11);
assertEquals(11, (int) f1ns.get(t));
assertEquals(11, (int) f1.get(t));
assertEquals(11, (int) t.f1);
assertEquals("b", f0.get(t));
assertEquals("b", t.f0);
// This is technically valid (the ".0" is selecting the 0th field of a basic type).
FieldAccessor<Tuple2<String, Integer>, String> f0f0 = FieldAccessorFactory.getAccessor(tpeInfo, "f0.0", null);
assertEquals("b", f0f0.get(t));
assertEquals("b", t.f0);
t = f0f0.set(t, "cc");
assertEquals("cc", f0f0.get(t));
assertEquals("cc", t.f0);
}
示例10: testIllegalTupleInPojoInTuple
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
@Test(expected = CompositeType.InvalidFieldReferenceException.class)
public void testIllegalTupleInPojoInTuple() {
Tuple2<String, Foo> t = Tuple2.of("aa", new Foo(8, Tuple2.of("ddd", 9L), (short) 2));
TupleTypeInfo<Tuple2<String, Foo>> tpeInfo =
(TupleTypeInfo<Tuple2<String, Foo>>) TypeExtractor.getForObject(t);
FieldAccessorFactory.getAccessor(tpeInfo, "illegal.illegal.illegal", null);
}
示例11: testValueStateDefault
import org.apache.flink.api.java.tuple.Tuple2; //導入方法依賴的package包/類
/**
* Tests simple value state queryable state instance with a default value
* set. Each source emits (subtaskIndex, 0)..(subtaskIndex, numElements)
* tuples, the key is mapped to 1 but key 0 is queried which should throw
* a {@link UnknownKeyOrNamespaceException} exception.
*
* @throws UnknownKeyOrNamespaceException thrown due querying a non-existent key
*/
@Test(expected = UnknownKeyOrNamespaceException.class)
public void testValueStateDefault() throws Throwable {
final Deadline deadline = TEST_TIMEOUT.fromNow();
final long numElements = 1024L;
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStateBackend(stateBackend);
env.setParallelism(maxParallelism);
// Very important, because cluster is shared between tests and we
// don't explicitly check that all slots are available before
// submitting.
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(Integer.MAX_VALUE, 1000L));
DataStream<Tuple2<Integer, Long>> source = env.addSource(new TestAscendingValueSource(numElements));
ValueStateDescriptor<Tuple2<Integer, Long>> valueState = new ValueStateDescriptor<>(
"any", source.getType(), Tuple2.of(0, 1337L));
// only expose key "1"
QueryableStateStream<Integer, Tuple2<Integer, Long>> queryableState = source.keyBy(
new KeySelector<Tuple2<Integer, Long>, Integer>() {
private static final long serialVersionUID = 4509274556892655887L;
@Override
public Integer getKey(Tuple2<Integer, Long> value) {
return 1;
}
}).asQueryableState("hakuna", valueState);
try (AutoCancellableJob autoCancellableJob = new AutoCancellableJob(cluster, env, deadline)) {
final JobID jobId = autoCancellableJob.getJobId();
final JobGraph jobGraph = autoCancellableJob.getJobGraph();
cluster.submitJobDetached(jobGraph);
// Now query
int key = 0;
CompletableFuture<ValueState<Tuple2<Integer, Long>>> future = getKvState(
deadline,
client,
jobId,
queryableState.getQueryableStateName(),
key,
BasicTypeInfo.INT_TYPE_INFO,
valueState,
true,
executor);
try {
future.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
} catch (ExecutionException | CompletionException e) {
// get() on a completedExceptionally future wraps the
// exception in an ExecutionException.
throw e.getCause();
}
}
}