BigQuery Streaming inserts with timestamp and unique row id

Viewed 89

How can we insert a timestamp and unique row id while inserting/streaming the data into a table using java SDK?

        Map<String, Object> metadata = new HashMap<>();
        metadata.put("table_name", "Users");
        metadata.put("timestamp", Instant.now().toString());
        metadata.put("Id", UUID.randomUUID(););
        metadata.put("is_processed", false);


        Queue<Map<String, Object>> queue = new LinkedList<>();
        queue.add(metadata);

        // convert the entries in queue to List<RowToInsert>
        List<InsertAllRequest.RowToInsert> rowsToInsert = queue
                .stream()
                .map(mapEntry -> InsertAllRequest.RowToInsert.of(mapEntry);)
                .collect(Collectors.toList());

        // prepare InsertAllRequest
        InsertAllRequest insertAllRequest = InsertAllRequest
                .newBuilder(getTableIdInstance("MetaData"))
                .setRows(rowsToInsert)
                .build();

        InsertAllResponse insertAllResponse = bqClient.insertAll(insertAllRequest);


Currently, I am using java functions to generate UUID and timestamp but checking bigquery can do this by default

0 Answers
Related