Java Code Examples for org.apache.flink.table.api.dataview.MapView#get()

The following examples show how to use org.apache.flink.table.api.dataview.MapView#get() . 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: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
public void accumulate(GenericRow acc, Object value, Long order) throws Exception {
	if (value != null) {
		T v = (T) value;
		Long prevOrder = (Long) acc.getField(1);
		if (prevOrder == null || prevOrder > order) {
			acc.setField(0, v); // acc.firstValue = v
			acc.setLong(1, order); // acc.firstOrder = order
		}

		MapView<Long, List<T>> orderToValueMapView = getOrderToValueMapViewFromAcc(acc);
		List<T> valueList = orderToValueMapView.get(order);
		if (valueList == null) {
			valueList = new ArrayList<>();
		}
		valueList.add(v);
		orderToValueMapView.put(order, valueList);
	}
}
 
Example 2
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
public void retract(GenericRow acc, Object value) throws Exception {
	if (value != null) {
		T v = (T) value;
		MapView<T, List<Long>> valueToOrderMapView = getValueToOrderMapViewFromAcc(acc);
		List<Long> orderList = valueToOrderMapView.get(v);
		if (orderList != null && orderList.size() > 0) {
			Long order = orderList.get(0);
			orderList.remove(0);
			if (orderList.isEmpty()) {
				valueToOrderMapView.remove(v);
			} else {
				valueToOrderMapView.put(v, orderList);
			}
			retract(acc, value, order);
		}
	}
}
 
Example 3
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
public void accumulate(GenericRow acc, Object value, Long order) throws Exception {
	if (value != null) {
		T v = (T) value;
		Long prevOrder = (Long) acc.getField(1);
		if (prevOrder == null || prevOrder <= order) {
			acc.setField(0, v); // acc.lastValue = v
			acc.setLong(1, order); // acc.lastOrder = order
		}

		MapView<Long, List<T>> orderToValueMapView = getOrderToValueMapViewFromAcc(acc);
		List<T> valueList = orderToValueMapView.get(order);
		if (valueList == null) {
			valueList = new ArrayList<>();
		}
		valueList.add(v);
		orderToValueMapView.put(order, valueList);
	}
}
 
Example 4
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
public void retract(GenericRow acc, Object value) throws Exception {
	if (value != null) {
		T v = (T) value;
		MapView<T, List<Long>> valueToOrderMapView = getValueToOrderMapViewFromAcc(acc);
		List<Long> orderList = valueToOrderMapView.get(v);
		if (orderList != null && orderList.size() > 0) {
			Long order = orderList.get(0);
			orderList.remove(0);
			if (orderList.isEmpty()) {
				valueToOrderMapView.remove(v);
			} else {
				valueToOrderMapView.put(v, orderList);
			}
			retract(acc, value, order);
		}
	}
}
 
Example 5
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
public void accumulate(GenericRowData acc, Object value, Long order) throws Exception {
	if (value != null) {
		T v = (T) value;
		Long prevOrder = (Long) acc.getField(1);
		if (prevOrder == null || prevOrder > order) {
			acc.setField(0, v); // acc.firstValue = v
			acc.setField(1, order); // acc.firstOrder = order
		}

		MapView<Long, List<T>> orderToValueMapView = getOrderToValueMapViewFromAcc(acc);
		List<T> valueList = orderToValueMapView.get(order);
		if (valueList == null) {
			valueList = new ArrayList<>();
		}
		valueList.add(v);
		orderToValueMapView.put(order, valueList);
	}
}
 
Example 6
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
public void retract(GenericRowData acc, Object value) throws Exception {
	if (value != null) {
		T v = (T) value;
		MapView<T, List<Long>> valueToOrderMapView = getValueToOrderMapViewFromAcc(acc);
		List<Long> orderList = valueToOrderMapView.get(v);
		if (orderList != null && orderList.size() > 0) {
			Long order = orderList.get(0);
			orderList.remove(0);
			if (orderList.isEmpty()) {
				valueToOrderMapView.remove(v);
			} else {
				valueToOrderMapView.put(v, orderList);
			}
			retract(acc, value, order);
		}
	}
}
 
Example 7
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
public void accumulate(GenericRowData acc, Object value, Long order) throws Exception {
	if (value != null) {
		T v = (T) value;
		Long prevOrder = (Long) acc.getField(1);
		if (prevOrder == null || prevOrder <= order) {
			acc.setField(0, v); // acc.lastValue = v
			acc.setField(1, order); // acc.lastOrder = order
		}

		MapView<Long, List<T>> orderToValueMapView = getOrderToValueMapViewFromAcc(acc);
		List<T> valueList = orderToValueMapView.get(order);
		if (valueList == null) {
			valueList = new ArrayList<>();
		}
		valueList.add(v);
		orderToValueMapView.put(order, valueList);
	}
}
 
Example 8
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
public void retract(GenericRowData acc, Object value) throws Exception {
	if (value != null) {
		T v = (T) value;
		MapView<T, List<Long>> valueToOrderMapView = getValueToOrderMapViewFromAcc(acc);
		List<Long> orderList = valueToOrderMapView.get(v);
		if (orderList != null && orderList.size() > 0) {
			Long order = orderList.get(0);
			orderList.remove(0);
			if (orderList.isEmpty()) {
				valueToOrderMapView.remove(v);
			} else {
				valueToOrderMapView.put(v, orderList);
			}
			retract(acc, value, order);
		}
	}
}
 
Example 9
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public void accumulate(GenericRow acc, Object value) throws Exception {
	if (value != null) {
		T v = (T) value;
		Long order = System.currentTimeMillis();
		MapView<T, List<Long>> valueToOrderMapView = getValueToOrderMapViewFromAcc(acc);
		List<Long> orderList = valueToOrderMapView.get(v);
		if (orderList == null) {
			orderList = new ArrayList<>();
		}
		orderList.add(order);
		valueToOrderMapView.put(v, orderList);
		accumulate(acc, value, order);
	}
}
 
Example 10
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public void retract(GenericRow acc, Object value, Long order) throws Exception {
	if (value != null) {
		T v = (T) value;
		MapView<Long, List<T>> orderToValueMapView = getOrderToValueMapViewFromAcc(acc);
		List<T> valueList = orderToValueMapView.get(order);
		if (valueList == null) {
			return;
		}
		int index = valueList.indexOf(v);
		if (index >= 0) {
			valueList.remove(index);
			if (valueList.isEmpty()) {
				orderToValueMapView.remove(order);
			} else {
				orderToValueMapView.put(order, valueList);
			}
		}
		if (v.equals(acc.getField(0))) { // v == acc.firstValue
			Long startKey = (Long) acc.getField(1);
			Iterator<Long> iter = orderToValueMapView.keys().iterator();
			// find the minimal order which is greater than or equal to `startKey`
			Long nextKey = Long.MAX_VALUE;
			while (iter.hasNext()) {
				Long key = iter.next();
				if (key >= startKey && key < nextKey) {
					nextKey = key;
				}
			}

			if (nextKey != Long.MAX_VALUE) {
				acc.setField(0, orderToValueMapView.get(nextKey).get(0));
				acc.setField(1, nextKey);
			} else {
				acc.setField(0, null);
				acc.setField(1, null);
			}
		}
	}
}
 
Example 11
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public void accumulate(GenericRow acc, Object value) throws Exception {
	if (value != null) {
		T v = (T) value;
		Long order = System.currentTimeMillis();
		MapView<T, List<Long>> valueToOrderMapView = getValueToOrderMapViewFromAcc(acc);
		List<Long> orderList = valueToOrderMapView.get(v);
		if (orderList == null) {
			orderList = new ArrayList<>();
		}
		orderList.add(order);
		valueToOrderMapView.put(v, orderList);
		accumulate(acc, value, order);
	}
}
 
Example 12
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public void retract(GenericRow acc, Object value, Long order) throws Exception {
	if (value != null) {
		T v = (T) value;
		MapView<Long, List<T>> orderToValueMapView = getOrderToValueMapViewFromAcc(acc);
		List<T> valueList = orderToValueMapView.get(order);
		if (valueList == null) {
			return;
		}
		int index = valueList.indexOf(v);
		if (index >= 0) {
			valueList.remove(index);
			if (valueList.isEmpty()) {
				orderToValueMapView.remove(order);
			} else {
				orderToValueMapView.put(order, valueList);
			}
		}
		if (v.equals(acc.getField(0))) { // v == acc.firstValue
			Long startKey = (Long) acc.getField(1);
			Iterator<Long> iter = orderToValueMapView.keys().iterator();
			// find the maximal order which is less than or equal to `startKey`
			Long nextKey = Long.MIN_VALUE;
			while (iter.hasNext()) {
				Long key = iter.next();
				if (key <= startKey && key > nextKey) {
					nextKey = key;
				}
			}

			if (nextKey != Long.MIN_VALUE) {
				List<T> values = orderToValueMapView.get(nextKey);
				acc.setField(0, values.get(values.size() - 1));
				acc.setField(1, nextKey);
			} else {
				acc.setField(0, null);
				acc.setField(1, null);
			}
		}
	}
}
 
Example 13
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public void accumulate(GenericRowData acc, Object value) throws Exception {
	if (value != null) {
		T v = (T) value;
		Long order = System.currentTimeMillis();
		MapView<T, List<Long>> valueToOrderMapView = getValueToOrderMapViewFromAcc(acc);
		List<Long> orderList = valueToOrderMapView.get(v);
		if (orderList == null) {
			orderList = new ArrayList<>();
		}
		orderList.add(order);
		valueToOrderMapView.put(v, orderList);
		accumulate(acc, value, order);
	}
}
 
Example 14
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public void retract(GenericRowData acc, Object value, Long order) throws Exception {
	if (value != null) {
		T v = (T) value;
		MapView<Long, List<T>> orderToValueMapView = getOrderToValueMapViewFromAcc(acc);
		List<T> valueList = orderToValueMapView.get(order);
		if (valueList == null) {
			return;
		}
		int index = valueList.indexOf(v);
		if (index >= 0) {
			valueList.remove(index);
			if (valueList.isEmpty()) {
				orderToValueMapView.remove(order);
			} else {
				orderToValueMapView.put(order, valueList);
			}
		}
		if (v.equals(acc.getField(0))) { // v == acc.firstValue
			Long startKey = (Long) acc.getField(1);
			Iterator<Long> iter = orderToValueMapView.keys().iterator();
			// find the minimal order which is greater than or equal to `startKey`
			Long nextKey = Long.MAX_VALUE;
			while (iter.hasNext()) {
				Long key = iter.next();
				if (key >= startKey && key < nextKey) {
					nextKey = key;
				}
			}

			if (nextKey != Long.MAX_VALUE) {
				acc.setField(0, orderToValueMapView.get(nextKey).get(0));
				acc.setField(1, nextKey);
			} else {
				acc.setField(0, null);
				acc.setField(1, null);
			}
		}
	}
}
 
Example 15
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public void accumulate(GenericRowData acc, Object value) throws Exception {
	if (value != null) {
		T v = (T) value;
		Long order = System.currentTimeMillis();
		MapView<T, List<Long>> valueToOrderMapView = getValueToOrderMapViewFromAcc(acc);
		List<Long> orderList = valueToOrderMapView.get(v);
		if (orderList == null) {
			orderList = new ArrayList<>();
		}
		orderList.add(order);
		valueToOrderMapView.put(v, orderList);
		accumulate(acc, value, order);
	}
}
 
Example 16
Source File: LastValueWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public void retract(GenericRowData acc, Object value, Long order) throws Exception {
	if (value != null) {
		T v = (T) value;
		MapView<Long, List<T>> orderToValueMapView = getOrderToValueMapViewFromAcc(acc);
		List<T> valueList = orderToValueMapView.get(order);
		if (valueList == null) {
			return;
		}
		int index = valueList.indexOf(v);
		if (index >= 0) {
			valueList.remove(index);
			if (valueList.isEmpty()) {
				orderToValueMapView.remove(order);
			} else {
				orderToValueMapView.put(order, valueList);
			}
		}
		if (v.equals(acc.getField(0))) { // v == acc.firstValue
			Long startKey = (Long) acc.getField(1);
			Iterator<Long> iter = orderToValueMapView.keys().iterator();
			// find the maximal order which is less than or equal to `startKey`
			Long nextKey = Long.MIN_VALUE;
			while (iter.hasNext()) {
				Long key = iter.next();
				if (key <= startKey && key > nextKey) {
					nextKey = key;
				}
			}

			if (nextKey != Long.MIN_VALUE) {
				List<T> values = orderToValueMapView.get(nextKey);
				acc.setField(0, values.get(values.size() - 1));
				acc.setField(1, nextKey);
			} else {
				acc.setField(0, null);
				acc.setField(1, null);
			}
		}
	}
}