How to insert Repeated Record in BigQuery using java client library

53
June 26, 2022, at 09:00 AM

I am very new to BigQuery and need help to resolve below mentioned query.

I am trying to insert data into a table similarly as mentioned below. I am able to insert record with BQ SQL. But need to understand how to achieve the same with java BQ client library.

Schema:

id: INTEGER NULLABLE
courses : RECORD REPEATED
    language : STRING NULLABLE
    marks : INTEGER NULLABLE

Query:

INSERT INTO `projectid.datasetid,tableid' 
(id, courses)
values(1, [('Java', 80), (Python', 70)]

Table Result can be as below.

id  courses
1   language    marks   
    Java        80
    python      70

If courses is simple Array/List of Strings then i could have easily done with below mentioned code snippet

String[] cs = {"Java", "Python"}
QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(queryString)
.addNamedParameter("courses",QueryParameterValue.array(cs, String.class))

But with Custom Object i was expecting some thing like below but it is not available. There should be some other way to handle this.

class CustomObject {
private String language,
private Integer marks
}
CustomObject[] cs = {new CustomObject1("Java", 80), new CustomObject2("Python", 70)}
QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(queryString)
.addNamedParameter("courses",QueryParameterValue.array(cs, CustomObject.class))

There should be some other way to make this work. Please guide me

Rent Charter Buses Company
READ ALSO
How to execute methods after the OnCreateView?

How to execute methods after the OnCreateView?

I'm working on an Android app in Java where a class is called and measurements are made in the OnCreateView methodHowever I have to automate the sending of his measurements once finished

75
Can I capture accessibility events in Fire OS?

Can I capture accessibility events in Fire OS?

I have a Java Android app that captures accessibility events by overriding the onAccessibilityEvent() method in a custom AccessibilityService classIt works well on phones and tablets

62
Can we use github repository as an artifact while creating maven project?

Can we use github repository as an artifact while creating maven project?

I've implemented a maven library and published it to GitHubNow I wanted to use this repository as an archetype to create another maven project (without maven central repo) like below

70