private List<ReplicationMessage.Column> transform(List<PgProto.DatumMessage> messageList, List<PgProto.TypeInfo> typeInfoList) { return IntStream.range(0, messageList.size()) .mapToObj(index -> { final PgProto.DatumMessage datum = messageList.get(index); final Optional<PgProto.TypeInfo> typeInfo = Optional.ofNullable(hasTypeMetadata() && typeInfoList != null ? typeInfoList.get(index) : null); final String columnName = Strings.unquoteIdentifierPart(datum.getColumnName()); final PostgresType type = typeRegistry.get((int)datum.getColumnType()); return new AbstractReplicationMessageColumn(columnName, type, typeInfo.map(PgProto.TypeInfo::getModifier).orElse(null), typeInfo.map(PgProto.TypeInfo::getValueOptional).orElse(Boolean.FALSE), hasTypeMetadata()) { @Override public Object getValue(PgConnectionSupplier connection, boolean includeUnknownDatatypes) { return PgProtoReplicationMessage.this.getValue(datum, connection, includeUnknownDatatypes); } @Override public String toString() { return datum.toString(); } }; }) .collect(Collectors.toList()); }
public void unquoteIdentifierPartShouldReturnNullForNull() { assertThat(Strings.unquoteIdentifierPart(null)).isNull(); }
private void assertSchemaContent(String[] fields, Schema[] types, Schema keySchema) { IntStream.range(0, fields.length).forEach(i -> { String fieldName = fields[i].trim(); Field field = keySchema.field(Strings.unquoteIdentifierPart(fieldName)); assertNotNull(fieldName + " not found in schema", field); VerifyRecord.assertConnectSchemasAreEqual(fieldName, types[i], field.schema()); }); }
@Test public void unquoteIdentifierPartShouldSupportDoubleQuotes() { assertThat(Strings.unquoteIdentifierPart("\"Tab\"\"le\"")).isEqualTo("Tab\"le"); }
@Test public void unquoteIdentifierPartShouldReturnSameValueForUnquotedString() { assertThat(Strings.unquoteIdentifierPart("table")).isEqualTo("table"); }
@Test public void unquoteIdentifierPartShouldSupportBackTicks() { assertThat(Strings.unquoteIdentifierPart("`Tab``le`")).isEqualTo("Tab`le"); }
@Test public void unquoteIdentifierPartShouldReturnEmptyStringForEmptyQuotedString() { assertThat(Strings.unquoteIdentifierPart("''")).isEqualTo(""); }
@Test public void unquoteIdentifierPartShouldReturnUnquotedString() { assertThat(Strings.unquoteIdentifierPart("'Table'")).isEqualTo("Table"); }
@Test public void unquoteIdentifierPartShouldUnescapeEscapedQuote() { assertThat(Strings.unquoteIdentifierPart("'Tab''le'")).isEqualTo("Tab'le"); }
String columnName = Strings.unquoteIdentifierPart(column.getName()); int position = table.columnWithName(columnName).position() - 1; if (position < 0) {
private List<ReplicationMessage.Column> transform(List<PgProto.DatumMessage> messageList, List<PgProto.TypeInfo> typeInfoList) { return IntStream.range(0, messageList.size()) .mapToObj(index -> { final PgProto.DatumMessage datum = messageList.get(index); final Optional<PgProto.TypeInfo> typeInfo = Optional.ofNullable(hasTypeMetadata() && typeInfoList != null ? typeInfoList.get(index) : null); final String columnName = Strings.unquoteIdentifierPart(datum.getColumnName()); final PostgresType type = typeRegistry.get((int)datum.getColumnType()); return new AbstractReplicationMessageColumn(columnName, type, typeInfo.map(PgProto.TypeInfo::getModifier).orElse(null), typeInfo.map(PgProto.TypeInfo::getValueOptional).orElse(Boolean.FALSE), hasTypeMetadata()) { @Override public Object getValue(PgConnectionSupplier connection, boolean includeUnknownDatatypes) { return PgProtoReplicationMessage.this.getValue(datum, connection, includeUnknownDatatypes); } @Override public String toString() { return datum.toString(); } }; }) .collect(Collectors.toList()); }
private void assertSchemaContent(String[] fields, Schema[] types, Schema keySchema) { IntStream.range(0, fields.length).forEach(i -> { String fieldName = fields[i].trim(); Field field = keySchema.field(Strings.unquoteIdentifierPart(fieldName)); assertNotNull(fieldName + " not found in schema", field); VerifyRecord.assertConnectSchemasAreEqual(fieldName, types[i], field.schema()); }); }
String columnName = Strings.unquoteIdentifierPart(column.getName()); int position = table.columnWithName(columnName).position() - 1; if (position < 0) {