columnName)); byte[] columnValue = column.getValue(); String ecValue = UTF8Type.instance.compose(ByteBuffer.wrap(columnValue));
return UTF8Type.instance.decompose((String) value);
private static String stringify(ByteBuffer name) { try { return UTF8Type.instance.getString(name); } catch (Exception e) { return ByteBufferUtil.bytesToHex(name); } } }
public static List<ByteBuffer> rowToJson(List<ByteBuffer> row, ProtocolVersion protocolVersion, ResultSet.ResultMetadata metadata) { StringBuilder sb = new StringBuilder("{"); for (int i = 0; i < metadata.names.size(); i++) { if (i > 0) sb.append(", "); ColumnSpecification spec = metadata.names.get(i); String columnName = spec.name.toString(); if (!columnName.equals(columnName.toLowerCase(Locale.US))) columnName = "\"" + columnName + "\""; ByteBuffer buffer = row.get(i); sb.append('"'); sb.append(Json.quoteAsJsonString(columnName)); sb.append("\": "); if (buffer == null || !buffer.hasRemaining()) sb.append("null"); else sb.append(spec.type.toJSONString(buffer, protocolVersion)); } sb.append("}"); return Collections.singletonList(UTF8Type.instance.getSerializer().serialize(sb.toString())); }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a UTF-8 string, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
int cmp = UTF8Type.instance.compare(a.collectionName.name.bytes, b.collectionName.name.bytes); if (cmp != 0) return cmp;
public static List<ByteBuffer> rowToJson(List<ByteBuffer> row, ProtocolVersion protocolVersion, ResultSet.ResultMetadata metadata) { StringBuilder sb = new StringBuilder("{"); for (int i = 0; i < metadata.getColumnCount(); i++) { if (i > 0) sb.append(", "); ColumnSpecification spec = metadata.names.get(i); String columnName = spec.name.toString(); if (!columnName.equals(columnName.toLowerCase(Locale.US))) columnName = "\"" + columnName + "\""; ByteBuffer buffer = row.get(i); sb.append('"'); sb.append(Json.quoteAsJsonString(columnName)); sb.append("\": "); if (buffer == null) sb.append("null"); else if (!buffer.hasRemaining()) sb.append("\"\""); else sb.append(spec.type.toJSONString(buffer, protocolVersion)); } sb.append("}"); List<ByteBuffer> jsonRow = new ArrayList<>(); jsonRow.add(UTF8Type.instance.getSerializer().serialize(sb.toString())); return jsonRow; }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a UTF-8 string, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
int cmp = UTF8Type.instance.compare(a.collectionName.name.bytes, b.collectionName.name.bytes); if (cmp != 0) return cmp;
@Override public String toString() { return UTF8Type.instance.compose(bytes); }
@Override public String toString() { return String.format("%s.%s", selected, UTF8Type.instance.getString(type.fieldName(field))); } }
public static List<ByteBuffer> rowToJson(List<ByteBuffer> row, ProtocolVersion protocolVersion, ResultSet.ResultMetadata metadata) { StringBuilder sb = new StringBuilder("{"); for (int i = 0; i < metadata.getColumnCount(); i++) { if (i > 0) sb.append(", "); ColumnSpecification spec = metadata.names.get(i); String columnName = spec.name.toString(); if (!columnName.equals(columnName.toLowerCase(Locale.US))) columnName = "\"" + columnName + "\""; ByteBuffer buffer = row.get(i); sb.append('"'); sb.append(Json.quoteAsJsonString(columnName)); sb.append("\": "); if (buffer == null) sb.append("null"); else if (!buffer.hasRemaining()) sb.append("\"\""); else sb.append(spec.type.toJSONString(buffer, protocolVersion)); } sb.append("}"); List<ByteBuffer> jsonRow = new ArrayList<>(); jsonRow.add(UTF8Type.instance.getSerializer().serialize(sb.toString())); return jsonRow; }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a UTF-8 string, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
int cmp = UTF8Type.instance.compare(a.collectionName.name.bytes, b.collectionName.name.bytes); if (cmp != 0) return cmp;
@Override public String toString() { return UTF8Type.instance.compose(bytes); }
asList.add(UTF8Type.instance.decompose(colName));
private static String stringify(ByteBuffer name) { try { return UTF8Type.instance.getString(name); } catch (Exception e) { return ByteBufferUtil.bytesToHex(name); } } }
public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters) { assert parameters.size() == 1 : "Unexpectedly got " + parameters.size() + " arguments for fromJson()"; ByteBuffer argument = parameters.get(0); if (argument == null) return null; String jsonArg = UTF8Type.instance.getSerializer().deserialize(argument); try { Object object = Json.JSON_OBJECT_MAPPER.readValue(jsonArg, Object.class); if (object == null) return null; return returnType.fromJSONObject(object).bindAndGet(QueryOptions.forProtocolVersion(protocolVersion)); } catch (IOException exc) { throw new FunctionExecutionException(NAME, Collections.singletonList("text"), String.format("Could not decode JSON string '%s': %s", jsonArg, exc.toString())); } catch (MarshalException exc) { throw FunctionExecutionException.create(this, exc); } } }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a UTF-8 string, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }