Reputation: 69
I am using the Streaming Insert function insertAll() to insert data into my Big Query table.
I am using a Map and List as shown in the Java code example in BQ Docs - bq docs link
Map<String, Object> row = new HashMap<>();
List<InsertAllRequest.RowToInsert> rowContent = new ArrayList<>();
The map row
has data of each column of a row and after reading the whole row, I'm adding it to rowContent
. Later I'm passing it to the insertAll()
function which takes a iterable declared like this:
Iterable<InsertAllRequest.RowToInsert> rows
NOW MY MAIN QUESTION IS HERE:
I am adding each column of a row to the Map by referencing the BQ Column name like:
row.put("columnName", value)
Is there a way to use column numbers instead of names?
For ex:
row.put(0, value0)
row.put(1, value1)
row.put(2, value2)
Upvotes: 0
Views: 398
Reputation: 75725
AFAIK, it's not an orderedMap and I would say NO. However, you can cheat.
Use an array of ColumnName
// Init
String[] columnNames = new String[3];
columnNames[0] = "Column1";
columnNames[1] = "Column2";
columnNames[2] = "Column3";
Then, in your put
do this
row.put(columnNames[0], value0)
row.put(columnNames[1], value1)
row.put(columnNames[2], value2)
You can even imagine to create your columnNames
array dynamically by reading the table metadata before starting the streaming.
Upvotes: 1