热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.flink.api.common.operators.Keys类的使用及代码示例

本文整理了Java中org.apache.flink.api.common.operators.Keys类的一些代码示例,展示了Keys类的具

本文整理了Java中org.apache.flink.api.common.operators.Keys类的一些代码示例,展示了Keys类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Keys类的具体详情如下:
包路径:org.apache.flink.api.common.operators.Keys
类名称:Keys

Keys介绍

暂无

代码示例

代码示例来源:origin: apache/flink

public TaggedValue getInput2AsTaggedValue() {
final int[] groupedKeys;
if (keys2 != null) {
groupedKeys = keys2.computeLogicalKeyPositions();
}
else {
groupedKeys = null;
}
return convertTypeInfoToTaggedValue(Input.INPUT_2, in2Type, "", null, groupedKeys);
}

代码示例来源:origin: apache/flink

public static KeySelector getSelectorForKeys(Keys keys, TypeInformation typeInfo, ExecutionConfig executionConfig) {
if (!(typeInfo instanceof CompositeType)) {
throw new InvalidTypesException(
"This key operation requires a composite type such as Tuples, POJOs, or Case Classes.");
}
CompositeType compositeType = (CompositeType) typeInfo;
int[] logicalKeyPositiOns= keys.computeLogicalKeyPositions();
int numKeyFields = logicalKeyPositions.length;
TypeInformation[] typeInfos = keys.getKeyFieldTypes();
// use ascending order here, the code paths for that are usually a slight bit faster
boolean[] orders = new boolean[numKeyFields];
for (int i = 0; i orders[i] = true;
}
TypeComparator comparator = compositeType.createComparator(logicalKeyPositions, orders, 0, executionConfig);
return new ComparableKeySelector<>(comparator, numKeyFields, new TupleTypeInfo<>(typeInfos));
}

代码示例来源:origin: apache/flink

public static KeySelector getSelectorForOneKey(
Keys keys, Partitioner partitioner, TypeInformation typeInfo, ExecutionConfig executionConfig) {
if (!(typeInfo instanceof CompositeType)) {
throw new InvalidTypesException(
"This key operation requires a composite type such as Tuples, POJOs, case classes, etc");
}
if (partitioner != null) {
keys.validateCustomPartitioner(partitioner, null);
}
CompositeType compositeType = (CompositeType) typeInfo;
int[] logicalKeyPositiOns= keys.computeLogicalKeyPositions();
if (logicalKeyPositions.length != 1) {
throw new IllegalArgumentException("There must be exactly 1 key specified");
}
TypeComparator comparator = compositeType.createComparator(
logicalKeyPositions, new boolean[] { true }, 0, executionConfig);
return new OneKeySelector<>(comparator);
}

代码示例来源:origin: apache/flink

private static Ordering computeOrdering(Keys pKeys, Order[] orders) {
Ordering ordering = new Ordering();
final int[] logicalKeyPositiOns= pKeys.computeLogicalKeyPositions();
if (orders == null) {
for (int key : logicalKeyPositions) {
ordering.appendOrdering(key, null, Order.ASCENDING);
}
} else {
final TypeInformation[] originalKeyFieldTypes = pKeys.getOriginalKeyFieldTypes();
int index = 0;
for (int i = 0; i final int typeTotalFields = originalKeyFieldTypes[i].getTotalFields();
for (int j = index; j ordering.appendOrdering(logicalKeyPositions[j], null, orders[i]);
}
index += typeTotalFields;
}
}
return ordering;
}

代码示例来源:origin: apache/flink

private

PartitionOperator(DataSet input, PartitionMethod pMethod, Keys pKeys, Partitioner

customPartitioner,
TypeInformation

partitionerTypeInfo, DataDistribution distribution, String partitionLocationName) {
super(input, input.getType());
Preconditions.checkNotNull(pMethod);
Preconditions.checkArgument(pKeys != null || pMethod == PartitionMethod.REBALANCE, "Partitioning requires keys");
Preconditions.checkArgument(pMethod != PartitionMethod.CUSTOM || customPartitioner != null, "Custom partioning requires a partitioner.");
Preconditions.checkArgument(distribution == null || pMethod == PartitionMethod.RANGE, "Customized data distribution is only neccessary for range partition.");
if (distribution != null) {
Preconditions.checkArgument(pKeys.getNumberOfKeyFields() <= distribution.getNumberOfFields(), "The distribution must provide at least as many fields as flat key fields are specified.");
Preconditions.checkArgument(Arrays.equals(pKeys.getKeyFieldTypes(), Arrays.copyOfRange(distribution.getKeyTypes(), 0, pKeys.getNumberOfKeyFields())),
"The types of the flat key fields must be equal to the types of the fields of the distribution.");
}
if (customPartitioner != null) {
pKeys.validateCustomPartitioner(customPartitioner, partitionerTypeInfo);
}
this.pMethod = pMethod;
this.pKeys = pKeys;
this.partitiOnLocationName= partitionLocationName;
this.customPartitiOner= customPartitioner;
this.distribution = distribution;
}

代码示例来源:origin: apache/flink

if (!keys1.areCompatible(keys2)) {
throw new InvalidProgramException("The types of the key fields do not match.");
int[] positiOns= keys1.computeLogicalKeyPositions();
((SolutionSetPlaceHolder) input1).checkJoinKeyFields(positions);
} else {
int[] positiOns= keys2.computeLogicalKeyPositions();
((SolutionSetPlaceHolder) input2).checkJoinKeyFields(positions);
} else {

代码示例来源:origin: apache/flink

/**
* Sets a custom partitioner for the CoGroup operation. The partitioner will be called on the join keys to determine
* the partition a key should be assigned to. The partitioner is evaluated on both inputs in the
* same way.
*
*

NOTE: A custom partitioner can only be used with single-field CoGroup keys, not with composite CoGroup keys.
*
* @param partitioner The custom partitioner to be used.
* @return This CoGroup operator, to allow for function chaining.
*/
public CoGroupOperator withPartitioner(Partitioner partitioner) {
if (partitioner != null) {
keys1.validateCustomPartitioner(partitioner, null);
keys2.validateCustomPartitioner(partitioner, null);
}
this.customPartitiOner= getInput1().clean(partitioner);
return this;
}

代码示例来源:origin: apache/flink

/**
* Check if two sets of keys are compatible to each other (matching types, key counts)
*/
public boolean areCompatible(Keys other) throws IncompatibleKeysException {
TypeInformation[] thisKeyFieldTypes = this.getKeyFieldTypes();
TypeInformation[] otherKeyFieldTypes = other.getKeyFieldTypes();
if (thisKeyFieldTypes.length != otherKeyFieldTypes.length) {
throw new IncompatibleKeysException(IncompatibleKeysException.SIZE_MISMATCH_MESSAGE);
} else {
for (int i = 0; i if (!thisKeyFieldTypes[i].equals(otherKeyFieldTypes[i])) {
throw new IncompatibleKeysException(thisKeyFieldTypes[i], otherKeyFieldTypes[i] );
}
}
}
return true;
}

代码示例来源:origin: apache/flink

public boolean isEmpty() {
return getNumberOfKeyFields() == 0;
}

代码示例来源:origin: apache/flink

/**
* Sets the order of keys for range partitioning.
* NOTE: Only valid for {@link PartitionMethod#RANGE}.
*
* @param orders array of orders for each specified partition key
* @return The partitioneOperator with properly set orders for given keys
*/
@PublicEvolving
public PartitionOperator withOrders(Order... orders) {
Preconditions.checkState(pMethod == PartitionMethod.RANGE, "Orders cannot be applied for %s partition " +
"method", pMethod);
Preconditions.checkArgument(pKeys.getOriginalKeyFieldTypes().length == orders.length, "The number of key " +
"fields and orders should be the same.");
this.orders = orders;
return this;
}

代码示例来源:origin: apache/flink

@Test
public void testAreCompatible1() throws Keys.IncompatibleKeysException {
TypeInformation t1 = TypeExtractor.getForClass(Pojo2.class);
TypeInformation> t2 =
new TupleTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
Keys k1 = new Keys.SelectorFunctionKeys<>(
new KeySelector1(),
t1,
BasicTypeInfo.STRING_TYPE_INFO
);
Keys> k2 = new Keys.SelectorFunctionKeys<>(
new KeySelector2(),
t2,
BasicTypeInfo.STRING_TYPE_INFO
);
Assert.assertTrue(k1.areCompatible(k2));
Assert.assertTrue(k2.areCompatible(k1));
}

代码示例来源:origin: apache/flink

public Grouping(DataSet set, Keys keys) {
if (set == null || keys == null) {
throw new NullPointerException();
}
if (keys.isEmpty()) {
throw new InvalidProgramException("The grouping keys must not be empty.");
}
this.inputDataSet = set;
this.keys = keys;
}

代码示例来源:origin: apache/flink

String name = getName() != null ? getName() : "CoGroup at " + defaultName;
try {
keys1.areCompatible(keys2);
} catch (IncompatibleKeysException e) {
throw new InvalidProgramException("The types of the key fields do not match.", e);
keys1.areCompatible(keys2);
} catch (IncompatibleKeysException e) {
throw new InvalidProgramException("The types of the key fields do not match.", e);
int[] logicalKeyPositions1 = keys1.computeLogicalKeyPositions();
int[] logicalKeyPositions2 = keys2.computeLogicalKeyPositions();

代码示例来源:origin: com.alibaba.blink/flink-java

private

PartitionOperator(DataSet input, PartitionMethod pMethod, Keys pKeys, Partitioner

customPartitioner,
TypeInformation

partitionerTypeInfo, DataDistribution distribution, String partitionLocationName) {
super(input, input.getType());
Preconditions.checkNotNull(pMethod);
Preconditions.checkArgument(pKeys != null || pMethod == PartitionMethod.REBALANCE, "Partitioning requires keys");
Preconditions.checkArgument(pMethod != PartitionMethod.CUSTOM || customPartitioner != null, "Custom partioning requires a partitioner.");
Preconditions.checkArgument(distribution == null || pMethod == PartitionMethod.RANGE, "Customized data distribution is only neccessary for range partition.");
if (distribution != null) {
Preconditions.checkArgument(pKeys.getNumberOfKeyFields() <= distribution.getNumberOfFields(), "The distribution must provide at least as many fields as flat key fields are specified.");
Preconditions.checkArgument(Arrays.equals(pKeys.getKeyFieldTypes(), Arrays.copyOfRange(distribution.getKeyTypes(), 0, pKeys.getNumberOfKeyFields())),
"The types of the flat key fields must be equal to the types of the fields of the distribution.");
}
if (customPartitioner != null) {
pKeys.validateCustomPartitioner(customPartitioner, partitionerTypeInfo);
}
this.pMethod = pMethod;
this.pKeys = pKeys;
this.partitiOnLocationName= partitionLocationName;
this.customPartitiOner= customPartitioner;
this.distribution = distribution;
}

代码示例来源:origin: com.alibaba.blink/flink-java

private static Ordering computeOrdering(Keys pKeys, Order[] orders) {
Ordering ordering = new Ordering();
final int[] logicalKeyPositiOns= pKeys.computeLogicalKeyPositions();
if (orders == null) {
for (int key : logicalKeyPositions) {
ordering.appendOrdering(key, null, Order.ASCENDING);
}
} else {
final TypeInformation[] originalKeyFieldTypes = pKeys.getOriginalKeyFieldTypes();
int index = 0;
for (int i = 0; i final int typeTotalFields = originalKeyFieldTypes[i].getTotalFields();
for (int j = index; j ordering.appendOrdering(logicalKeyPositions[j], null, orders[i]);
}
index += typeTotalFields;
}
}
return ordering;
}

代码示例来源:origin: apache/flink

/**
* Sets a custom partitioner for this join. The partitioner will be called on the join keys to determine
* the partition a key should be assigned to. The partitioner is evaluated on both join inputs in the
* same way.
*
*

NOTE: A custom partitioner can only be used with single-field join keys, not with composite join keys.
*
* @param partitioner The custom partitioner to be used.
* @return This join operator, to allow for function chaining.
*/
public JoinOperator withPartitioner(Partitioner partitioner) {
if (partitioner != null) {
keys1.validateCustomPartitioner(partitioner, null);
keys2.validateCustomPartitioner(partitioner, null);
}
this.customPartitiOner= getInput1().clean(partitioner);
return this;
}

代码示例来源:origin: org.apache.flink/flink-core

/**
* Check if two sets of keys are compatible to each other (matching types, key counts)
*/
public boolean areCompatible(Keys other) throws IncompatibleKeysException {
TypeInformation[] thisKeyFieldTypes = this.getKeyFieldTypes();
TypeInformation[] otherKeyFieldTypes = other.getKeyFieldTypes();
if (thisKeyFieldTypes.length != otherKeyFieldTypes.length) {
throw new IncompatibleKeysException(IncompatibleKeysException.SIZE_MISMATCH_MESSAGE);
} else {
for (int i = 0; i if (!thisKeyFieldTypes[i].equals(otherKeyFieldTypes[i])) {
throw new IncompatibleKeysException(thisKeyFieldTypes[i], otherKeyFieldTypes[i] );
}
}
}
return true;
}

代码示例来源:origin: apache/flink

public SortedGrouping(DataSet set, Keys keys, Keys.SelectorFunctionKeys keySelector, Order order) {
super(set, keys);
if (!(this.keys instanceof Keys.SelectorFunctionKeys)) {
throw new InvalidProgramException("Sorting on KeySelector keys only works with KeySelector grouping.");
}
TypeInformation sortKeyType = keySelector.getKeyType();
if (!sortKeyType.isSortKeyType()) {
throw new InvalidProgramException("Key type " + sortKeyType + " is not sortable.");
}
this.groupSortKeyPositiOns= keySelector.computeLogicalKeyPositions();
for (int i = 0; i groupSortKeyPositions[i] += this.keys.getNumberOfKeyFields();
}
this.groupSortSelectorFunctiOnKey= keySelector;
this.groupSortOrders = new Order[groupSortKeyPositions.length];
Arrays.fill(this.groupSortOrders, order);
}

代码示例来源:origin: apache/flink

@Test
public void testOriginalTypes1() throws Keys.IncompatibleKeysException {
TypeInformation> t2 = new TupleTypeInfo<>(
BasicTypeInfo.INT_TYPE_INFO,
BasicTypeInfo.STRING_TYPE_INFO
);
Keys> k = new Keys.SelectorFunctionKeys<>(
new KeySelector2(),
t2,
BasicTypeInfo.STRING_TYPE_INFO
);
Assert.assertArrayEquals(
new TypeInformation[] { BasicTypeInfo.STRING_TYPE_INFO },
k.getOriginalKeyFieldTypes()
);
}

代码示例来源:origin: apache/flink

@Test
public void testAreCompatible3() throws Keys.IncompatibleKeysException {
TypeInformation t1 = BasicTypeInfo.STRING_TYPE_INFO;
TypeInformation t2 = TypeExtractor.getForClass(Pojo2.class);
Keys.ExpressionKeys ek1 = new Keys.ExpressionKeys<>("*", t1);
Keys sk2 = new Keys.SelectorFunctionKeys<>(
new KeySelector1(),
t2,
BasicTypeInfo.STRING_TYPE_INFO
);
Assert.assertTrue(sk2.areCompatible(ek1));
}

推荐阅读
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • 本文介绍了Swing组件的用法,重点讲解了图标接口的定义和创建方法。图标接口用来将图标与各种组件相关联,可以是简单的绘画或使用磁盘上的GIF格式图像。文章详细介绍了图标接口的属性和绘制方法,并给出了一个菱形图标的实现示例。该示例可以配置图标的尺寸、颜色和填充状态。 ... [详细]
  • 重入锁(ReentrantLock)学习及实现原理
    本文介绍了重入锁(ReentrantLock)的学习及实现原理。在学习synchronized的基础上,重入锁提供了更多的灵活性和功能。文章详细介绍了重入锁的特性、使用方法和实现原理,并提供了类图和测试代码供读者参考。重入锁支持重入和公平与非公平两种实现方式,通过对比和分析,读者可以更好地理解和应用重入锁。 ... [详细]
  • 本文整理了Java中org.gwtbootstrap3.client.ui.Icon.addDomHandler()方法的一些代码示例,展示了Icon.ad ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
  • JVM 学习总结(三)——对象存活判定算法的两种实现
    本文介绍了垃圾收集器在回收堆内存前确定对象存活的两种算法:引用计数算法和可达性分析算法。引用计数算法通过计数器判定对象是否存活,虽然简单高效,但无法解决循环引用的问题;可达性分析算法通过判断对象是否可达来确定存活对象,是主流的Java虚拟机内存管理算法。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文详细介绍了Java中vector的使用方法和相关知识,包括vector类的功能、构造方法和使用注意事项。通过使用vector类,可以方便地实现动态数组的功能,并且可以随意插入不同类型的对象,进行查找、插入和删除操作。这篇文章对于需要频繁进行查找、插入和删除操作的情况下,使用vector类是一个很好的选择。 ... [详细]
  • 闭包一直是Java社区中争论不断的话题,很多语言都支持闭包这个语言特性,闭包定义了一个依赖于外部环境的自由变量的函数,这个函数能够访问外部环境的变量。本文以JavaScript的一个闭包为例,介绍了闭包的定义和特性。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • Android系统源码分析Zygote和SystemServer启动过程详解
    本文详细解析了Android系统源码中Zygote和SystemServer的启动过程。首先介绍了系统framework层启动的内容,帮助理解四大组件的启动和管理过程。接着介绍了AMS、PMS等系统服务的作用和调用方式。然后详细分析了Zygote的启动过程,解释了Zygote在Android启动过程中的决定作用。最后通过时序图展示了整个过程。 ... [详细]
author-avatar
爱啊诗的孩子
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有