public String getDetailedMessage(Type keyType, ConnectorSession session) { return format("Duplicate map keys (%s) are not allowed", keyType.getObjectValue(session, block, position)); } }
public Object getPrintableValue(ConnectorSession session) { if (!valueBlock.isPresent()) { throw new IllegalStateException("No value to get"); } return type.getObjectValue(session, valueBlock.get(), 0); }
private List<Object> arrayBlockToObjectValues(ConnectorSession session, Block block, int start, int length) { List<Object> values = new ArrayList<>(length); for (int i = 0; i < length; i++) { values.add(elementType.getObjectValue(session, block, i + start)); } return Collections.unmodifiableList(values); }
public static Object getJsonObjectValue(Type valueType, ConnectorSession session, Block block, int position) { Object objectValue = valueType.getObjectValue(session, block, position); if (objectValue instanceof SqlDecimal) { objectValue = ((SqlDecimal) objectValue).toBigDecimal(); } return objectValue; } }
@Override public String toString(ConnectorSession session) { return (whiteList ? "[ " : "EXCLUDES[ ") + entries.stream() .map(entry -> type.getObjectValue(session, entry.getBlock(), 0).toString()) .collect(Collectors.joining(", ")) + " ]"; }
private static OptionalLong getIntegerValue(ConnectorSession session, Type type, Block block) { // works for BIGINT as well as for other integer types TINYINT/SMALLINT/INTEGER that store values as byte/short/int return block.isNull(0) ? OptionalLong.empty() : OptionalLong.of(((Number) type.getObjectValue(session, block, 0)).longValue()); }
private static void assertBlockEquals(Type type, Block actual, Block expected) { for (int position = 0; position < actual.getPositionCount(); position++) { assertEquals(type.getObjectValue(SESSION, actual, position), type.getObjectValue(SESSION, expected, position)); } } }
private static void assertBlockEquals(Type type, Block actual, Block expected) { for (int position = 0; position < actual.getPositionCount(); position++) { assertEquals(type.getObjectValue(SESSION, actual, position), type.getObjectValue(SESSION, expected, position)); } } }
private static OptionalDouble getDoubleValue(ConnectorSession session, Type type, Block block) { return block.isNull(0) ? OptionalDouble.empty() : OptionalDouble.of(((Number) type.getObjectValue(session, block, 0)).doubleValue()); }
private static Object toTypeObjectValue(Session session, Type type, Object value) { BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); writeNativeValue(type, blockBuilder, value); return type.getObjectValue(session.toConnectorSession(), blockBuilder, 0); } }
public static Object getOnlyValue(Type type, Block block) { assertEquals(block.getPositionCount(), 1, "Block positions"); return type.getObjectValue(SESSION, block, 0); }
public static List<Object> toValues(Type type, Block block) { List<Object> values = new ArrayList<>(); for (int position = 0; position < block.getPositionCount(); position++) { values.add(type.getObjectValue(SESSION, block, position)); } return Collections.unmodifiableList(values); }
private static SortedMap<Integer, Object> indexObjectValues(Type type, Block block) { SortedMap<Integer, Object> values = new TreeMap<>(); for (int position = 0; position < block.getPositionCount(); position++) { values.put(position, type.getObjectValue(SESSION, block, position)); } return unmodifiableSortedMap(values); } }
private static Map toMapValue(Block mapBlock, Type keyType, Type valueType) { Map<Object, Object> map = new HashMap<>(mapBlock.getPositionCount() * 2); for (int i = 0; i < mapBlock.getPositionCount(); i += 2) { map.put(keyType.getObjectValue(SESSION, mapBlock, i), valueType.getObjectValue(SESSION, mapBlock, i + 1)); } return Collections.unmodifiableMap(map); }
private static Object decodeObject(Type type, Block block, int position) { if (block.isNull(position)) { return null; } return type.getObjectValue(SESSION, block, position); } }
private static List toArrayValue(Block arrayBlock, Type elementType) { List<Object> values = new ArrayList<>(); for (int position = 0; position < arrayBlock.getPositionCount(); position++) { values.add(elementType.getObjectValue(SESSION, arrayBlock, position)); } return Collections.unmodifiableList(values); }
public static List<Object> toValues(Type type, Iterable<Block> blocks) { List<Object> values = new ArrayList<>(); for (Block block : blocks) { for (int position = 0; position < block.getPositionCount(); position++) { values.add(type.getObjectValue(SESSION, block, position)); } } return Collections.unmodifiableList(values); }
private static List toRowValue(Block rowBlock, List<Type> fieldTypes) { List<Object> values = new ArrayList<>(rowBlock.getPositionCount()); for (int i = 0; i < rowBlock.getPositionCount(); i++) { values.add(fieldTypes.get(i).getObjectValue(SESSION, rowBlock, i)); } return Collections.unmodifiableList(values); }
public static void assertBlockEquals(Type type, Block actual, Block expected) { assertEquals(actual.getPositionCount(), expected.getPositionCount()); for (int position = 0; position < actual.getPositionCount(); position++) { assertEquals(type.getObjectValue(SESSION, actual, position), type.getObjectValue(SESSION, expected, position)); } }
private Object selectSingleValue(Operator operator, Type type) { Page output = getAtMostOnePage(operator, SOURCE_PAGE); assertNotNull(output); assertEquals(output.getPositionCount(), 1); assertEquals(output.getChannelCount(), 1); Block block = output.getBlock(0); assertEquals(block.getPositionCount(), 1); return type.getObjectValue(session.toConnectorSession(), block, 0); }