-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I specify CURRENT_TIMESTAMP for rows by Storage Write API? #531
Comments
I also noticed a new problem. If I set the default value of a column of type timestamp to CURRENT_TIMESTAMP, and then add data with that column unspecified using the Storage Write API, the value is always If I do the same with an INSERT query, it works fine, and if I specify Is this a bug? |
@mikan3rd thanks for the report. The BigQuery Storage Write API doesn't support using SQL expressions for row values. An alternative for that is to rely on the column default value, which can be set to There is an integration test here with examples on how to use that:
References |
Thanks for the reply. I tried specifying Can you please check if there is a bug in the operation? For reference, here is the code I am using. [
{
"name": "memo",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "created_at",
"type": "TIMESTAMP",
"mode": "REQUIRED",
"defaultValueExpression": "CURRENT_TIMESTAMP()"
}
] import { adapt, managedwriter, protos } from '@google-cloud/bigquery-storage';
const rowsList = [[
{
memo: "test",
}
]]
const destinationTable = `projects/${projectId}/datasets/${datasetId}/tables/${tableId}`;
const writeClient = new WriterClient({ projectId });
try {
const writeStream = await writeClient.getWriteStream({
streamId: `${destinationTable}/streams/_default`,
view: protos.google.cloud.bigquery.storage.v1.WriteStreamView.FULL,
});
const protoDescriptor = adapt.convertStorageSchemaToProto2Descriptor(writeStream.tableSchema!, 'root');
const connection = await writeClient.createStreamConnection({
streamId: managedwriter.DefaultStream,
destinationTable,
});
const writer = new JSONWriter({
connection,
protoDescriptor,
defaultMissingValueInterpretation: 'DEFAULT_VALUE',
});
const pendingWrites = rowsList.map((rows) => writer.appendRows(rows));
await Promise.all(
pendingWrites.map(async (pw) => {
const result = await pw.getResult();
if (result.error || result.rowErrors?.length) {
throw new AppendRowsError(result);
}
}),
);
} finally {
if (writeClient.isOpen()) {
writeClient.close();
}
} |
The integration test that I pointed out tests a similar scenario. I ran it here and it fills the missing values with the
Are you using the latest version of the library @mikan3rd ? Can you double check if the table indeed has the |
Thanks for the reply. I checked the schema again and confirmed that the However, the problem still persists when inserting data via the Storage Write API as in the code above, where the default value is not set correctly. We also tried I would appreciate it if you could check the actual behavior as well as the test. |
@mikan3rd sorry the the late reply, I was out for the holidays. After some further investigation, I found that the issue was related to protobufJS setting So I've opened PR #532 that sets the proto descriptor field to |
@alvarowolfx |
Please make sure you have searched for information in the following guides.
Documentation Request
For example, for a query, we can insert
CURRENT_TIMESTAMP
as followsHowever, in the case of Storage Write API, passing the string
“CURRENT_TIMESTAMP”
to appendRows did not result in correct data.Can I specify CURRENT_TIMESTAMP for rows by Storage Write API?
The text was updated successfully, but these errors were encountered: