> For the complete documentation index, see [llms.txt](https://trillo.gitbook.io/trillo-workbench-java-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trillo.gitbook.io/trillo-workbench-java-sdk/google-cloud-api-gcpapi/bigquery-bigqueryapi.md).

# BigQueryApi (BigQuery APIs)

## createTable

Create a new table in the data set identified by a table name and its schema.​

```
BigQueryApi.createTable(String datasetName, String tableName, Schema schema)

or

BigQueryApi.createTable(String datasetName, String tableName, List<Map<String, Object>> classAttrs)

or

BigQueryApi.createTable(String datasetName, String tableName,
      List<Map<String, Object>> csvSchema, List<Map<String, Object>> classAttrs, List<Map<String, Object>> mappings)
```

parameters:

```
datasetName: dataset name
tableName:   table name
schema:       schema object
classAttrs:   class attributes
csvSchema:     csv representation object
mappings:     mappings object
```

Return : result

```
the result object​
```

## getBQDataSets

Get the list of all dataset names.​

```
BigQueryApi.getBQDataSets()
```

parameters:

```
none​
```

Return:

```
list of objects​
```

## getBQTables

List the tables in a specific data set.​

```
BigQueryApi.getBQTables(String datasetName)
```

parameters:

```
datasetName: name of the data set
```

Return:

```
the list of the tables​
```

## getTable

Retrieves table information from the data set.​

```
BigQueryApi.getTable(String datasetName, String tableName) 
or
BigQueryApi.getTable(String datasetAndTableName)
```

parameters:

```
datasetName:  name of the data set
tableName:    name of the table
datasetAndTableName
```

Return:

```
detail information of the table​
```

## getTableFields

// Description //

```
BigQueryApi.getTableFields(String datasetAndTableName)
or
BigQueryApi.getTableFields(String datasetName, String tableName)
```

#### Parameters

```
datasetAndTableName
datasetName
tableName
```

#### Returns

```
List<Object>
```

## executeQuery

Executes a query in a specific data set and return the results.​

```
BigQueryApi.executeQuery(String queryString)
```

parameters:

```
queryString: query
```

Return:

```
the result object representing the query outcome.​
```

## getBigQueryIterator

Get an iterator over table query.

```
BigQueryApi.getBigQueryIterator(String query, int startIndex, int pageSize)
```

parameters:

```
query:      table query 
startIndex: index start
pageSize:    page size
```

Return:

```
iterator object​
```

## insertRows

Insert a list of rows into the table.​

```
BigQueryApi.insertRows(
      String datasetName, String tableName, List<Map<String, Object>> list)
```

parameters:

```
datasetName:   dataset name
tableName:     table in the data set
list:          records to be inserted
```

Return:

```
the result of the insertion​
```

## importCSVIntoTable

Import data from CSV file to the dataset table​. The header in the CSV file can be skipped if needed.&#x20;

```
BigQueryApi.importCSVIntoTable(String datasetName, String tableName, String pathToFile, 
      List<Map<String, Object>> csvSchema, List<Map<String, Object>> classAttrs, List<Map<String, Object>> mappings, int numberOfRowsToSkip)
      
or

BigQueryApi.importCSVIntoTable(String datasetName, String tableName, String pathToFile, Schema schema, int numberOfRowsToSkip)

or

BigQueryApi.importCSVIntoTable(String datasetName, String tableName, String path, String fileName, Schema schema, int numberOfRowsToSkip)
```

parameters:

```
datasetName:   name of the dataset
tableName:     name of the table in the data set
pathToFile:    absolute path to the file on the system
csvSchema:     the csv schema
classAttrs:    attributes 
mappings:      mapping of attributes with schema 
numberOfRowsToSkip:   if skipping rows from the top of the csv file
fileName:      the name of the file
schema:         the schema
```

Return:

```
the result of the operation​
```

## importCSVbyURIIntoTable

Same as above but using the URI for CSV file location.​

```
BigQueryApi.importCSVbyURIIntoTable(String datasetName, String tableName, String sourceUri, Schema schema, int numberOfRowsToSkip)
```

parameters:

```
datasetName:     name of the data set
tableName:       name of the table in the dataset
sourceUri:       the uri of source file
schema:           the scheme of the csv
numberOfRowsToSkip:   csv line to skip from the start
```

Return:

```
result of the operation​
```

## exportTableToCSV

Exports dataset table into a CSV file.​

```
BigQueryApi.exportTableToCSV(
      String datasetName,
      String tableName,
      String pathToFile)
or

BigQueryApi.exportTableToCSV(
      String datasetName,
      String tableName,
      String path, String fileName)
```

parameters:

```
datasetName:   name of the data set
tableName:     name of the table in the data set
pathToFile:    path to the CSV file
path:          same as above
fileName:      name of the file
```

Return:

```
the result of the operation​
```

## exportTableToCSVByURI

Same as above but using the URI for the csv file location

```
BigQueryApi.exportTableToCSVByURI(
      String datasetName,
      String tableName,
      String destinationUri)
```

parameters:

```
datasetName:   name of the data set
tableName:     name of the table in the data set
destinationUri:   the destination uri of csv file
```

Return:

```
the result of the operation​
```

## exportTable

Export a table​ of the dataset to a file type with the destination uri provided.

```
BigQueryApi.exportTable(
      String datasetName,
      String tableName,
      String destinationUri,
      String dataFormat)
```

parameters:

```
datasetName:   name of the dataset
tableName:     name of the table in the dataset
destinationUri:   destination uri
dataFormat:    format of the exported data
```

Return:

```
result of the operation​
```

## bigQueryToCSV

export data set table with specific columns to a CSV.​

```
BigQueryApi.bigQueryToCSV(String filePath, String[] columnNames, String dataSetName, String bqTableName,
      String query) 
or


BigQueryApi.bigQueryToCSV(String filePath, String[] columnNames, String dataSetName, String bqTableName,
        String query, String functionName)
```

parameters:

```
filePath:       the path of the CSV file
columnNames:    table column names
dataSetName:    name of the data set
bqTableName:    name of table
query:          query to run
functionName:   extra function to be called
```

Return:

```
the result of the operation​
```

## getpage

Get page details

```
BigQueryApi.getPage(String query, long start, long size)
```

#### Parameters

```
query
start
size
```

#### Returns

```
Object
```

## createTableFromCSV

Create table from CSV

<pre><code>BigQueryApi.createTableFromCSV(String datasetName, String tableName, String bucketFileName)
or
<strong>BigQueryApi.createTableFromCSV(String datasetName, String tableName, String bucketName, String bucketFileName)
</strong></code></pre>

#### Parameters

```
datasetName
tableName
bucketFileName
bucketName
```

#### Returns

```
Result
```

## importJSONbyURIIntoTable

import JSON by URI into table

```
BigQueryApi.importJSONbyURIIntoTable(String datasetName, String tableName,
                                               String sourceUri)
or 
BigQueryApi.importJSONbyURIIntoTable(String datasetName, String tableName,
                                                String sourceUri, Schema schema)
```

#### Parameters

```
datasetName
tableName
sourceUri
schema
```

#### Returns

```
Result
```

## bigQueryToCSVWithScript

Get page details

```
BigQueryApi.bigQueryToCSVWithScript(String filePath, String[] columnNames,
      String dataSetName, String bqTableName, String query, String script, String scriptFlavor)
```

#### Parameters

```
filePath
columnNames
dataSetName
bqTableName
query
script
scriptFlavor
```

#### Returns

```
int
```
