sqladmin v1beta4 - sql.instances.export - exports NULLs improperly to CSV
See original GitHub issueAs the title states, when using the sqladmin v1beta4 sql.instances.export functionality, upon export, records containing NULL values have their NULLs represented as "N by default – which plays hell on every CSV parser & BigQuery.
This was done using the googleapis v18.0.0 module.
Example Output:
# I have replaced all not-null values with categorical representations
# The, "N, values are the NULLs
"2017-03-27 18:37:54","N,"city","country","N,"N,lat,long,int,"message","ja-jp","Message","IE","Windows","11","URL","URL","URL","URL","HASH"
Here is my code:
'use strict';
(function() {
var google = require('googleapis');
var sqladmin = google.sqladmin('v1beta4');
module.exports = function exportCloudSqlToGCS(config) {
google.auth.getApplicationDefault(function(err, authClient) {
if (err) {
console.log('Authentication failed because of ', err);
return;
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
var scopes = [
// Needed for ability to import / export.
'https://www.googleapis.com/auth/cloud-platform',
// Needed to login to the MySQL database successfully.
'https://www.googleapis.com/auth/sqlservice.admin'
];
authClient = authClient.createScoped(scopes);
}
var request = {
// Project ID of the project that contains the instance to be exported.
project: config.gcloudProject, // 'my-project-name'
// Cloud SQL instance ID. This does not include the project ID.
instance: config.gcloudInstance, // 'my-cloud-sql-db-name'
resource: {
// Contains details about the export operation.
exportContext: {
// This is always sql#exportContext.
kind: "sql#exportContext",
// The file type for the specified uri (e.g. SQL or CSV)
fileType: config.exportFileType, // CSV
/**
* The path to the file in GCS where the export will be stored.
* The URI is in the form gs://bucketName/fileName.
* If the file already exists, the operation fails.
* If fileType is SQL and the filename ends with .gz, the contents are compressed.
*/
uri: config.gcsBucketFilePath,
/**
* Databases from which the export is made.
* If fileType is SQL and no database is specified, all databases are exported.
* If fileType is CSV, you can optionally specify at most one database to export.
* If csvExportOptions.selectQuery also specifies the database, this field will be ignored.
*/
databases: config.databases, // ['myDatabase']
// Options for exporting data as SQL statements.
// sqlExportOptions: {
// /**
// * Tables to export, or that were exported, from the specified database.
// * If you specify tables, specify one and only one database.
// */
// tables: config.tables,
// // Export only schemas?
// schemaOnly: config.schemaOnly
// },
csvExportOptions: {
// The select query used to extract the data.
selectQuery: config.selectQuery // "SELECT * from myTable"
}
}
},
// Auth client
auth: authClient
};
// Kick off export with requested arguments.
sqladmin.instances.export(request, function(err, result) {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
});
};
}).call(this);
I believe the proper NULL representation should be “\N” or at least an empty string, or simply, no value at all: value,value,value,value,value,value
This was likely a simple typo – but it is a pain. I’ve worked around it by wrapping every field in a simple IFNULL( fieldName, ‘’) as fieldName – but that’s rather tedious to maintain.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Method: instances.export | Cloud SQL for MySQL
Exports data from a Cloud SQL instance to a Cloud Storage bucket as a SQL dump or CSV file.
Read more >Understanding the behavior of gcloud sql export sql and ...
To achieve this, I decided to export the database of my instance, create a second one and import the exported backup of the...
Read more >CloudSQL import and export via CSV is implemented incorrectly
We're exporting from Cloud SQL to load into BigQuery. Our current work around is to replace all nulls with a string which acts...
Read more >sql.instances.export - Cloud SQL Admin - Any API
Exports data from a Cloud SQL instance to a Cloud Storage bucket as a SQL dump or CSV file.
Read more >ExportContext (Cloud SQL Admin API v1beta4 (Rev. 76) 1.25.0)
Database instance export context. ... Options for exporting data as SQL statements. ... Parameters: csvExportOptions - csvExportOptions or null for none ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any status update or timescales for this bug fix?
Allowing the “Escaped By” value to be configurable would be the best solution but in the short term could Poma’s suggestion of changing the escape character to \ be implemented? It would significant improve the compatible of exported files with other systems like BigQuery.
Hi @bllevy, Thanks for reporting this. That does sound annoying. We will look into it.