public void jsonColumn(Column column) { final JsonNode value = rowValues.get(column.getIndex()); if (value == null || value.isNull()) { pageBuilder.setNull(column); } else { try { pageBuilder.setJson(column, jsonParser.parse(value.toString())); } catch (JsonParseException ex) { throw new DataException(ex); } } } });
long lineNumber = tokenizer.getCurrentLineNumber(); if (stopOnInvalidRecord) { throw new DataException(String.format("Invalid record at %s:%d: %s", fileName, lineNumber, skippedLine), e); logger.warn(String.format("Skipped line %s:%d (%s): %s", fileName, lineNumber, e.getMessage(), skippedLine));
public void timestampColumn(Column column) { final JsonNode value = rowValues.get(column.getIndex()); if (value == null || value.isNull()) { pageBuilder.setNull(column); } else { try { pageBuilder.setTimestamp(column, timestampParsers[column.getIndex()].parse(value.asText())); } catch (TimestampParseException ex) { throw new DataException(ex); } } }
} catch (JsonRecordValidateException e) { if (stopOnInvalidRecord) { throw new DataException(String.format("Invalid record in %s: %s", fileName, value.toJson()), e); throw new DataException(String.format("Failed to parse JSON: %s", fileName), e);
private JsonNode parseJson(final String json) throws DataException { try { return this.jsonMapper.readTree(json); } catch (IOException ex) { throw new DataException(ex); } }
@Override public void decodeFromJsonTo(PreparedStatement toStatement, int toIndex, JsonNode fromValue) throws SQLException { throw new DataException(String.format(ENGLISH, "Converting last_record value %s to column index %d is not supported", fromValue.toString(), toIndex)); } }
public List<JsonNode> getList() { ImmutableList.Builder<JsonNode> builder = ImmutableList.builder(); for (int i = 0; i < lastValues.length; i++) { if (lastValues[i] == null || lastValues[i].isNull()) { throw new DataException(String.format(ENGLISH, "incremental_columns can't include null values but the last row is null at column '%s'", columnNames.get(i))); } builder.add(lastValues[i]); } return builder.build(); } }
@Override public JsonNode encodeToJson() { throw new DataException(String.format(ENGLISH, "Column type '%s' set at incremental_columns option is not supported", getToType())); }
public void push(JsonNode records, PluginTask task) { int bulkActions = task.getBulkActions(); long bulkSize = task.getBulkSize(); // curl -xPOST localhost:9200/{index}/{type}/_bulk -d ' // {"index" : {}}\n // {"k" : "v"}\n // {"index" : {}}\n // {"k" : "v2"}\n // ' try { String path = String.format("/%s/%s/_bulk", task.getIndex(), task.getType()); int recordSize = records.size(); String idColumn = task.getId().orElse(null); if (recordSize > 0) { StringBuilder sb = new StringBuilder(); for (JsonNode record : records) { sb.append(createIndexRequest(idColumn, record)); String requestString = jsonMapper.writeValueAsString(record); sb.append("\n") .append(requestString) .append("\n"); } sendRequest(path, HttpMethod.POST, task, sb.toString()); } } catch (JsonProcessingException ex) { throw new DataException(ex); } }