Skip to content

Picosecond support#1365

Open
KanchanShu wants to merge 1 commit into
mainfrom
picosecond_support
Open

Picosecond support#1365
KanchanShu wants to merge 1 commit into
mainfrom
picosecond_support

Conversation

@KanchanShu

@KanchanShu KanchanShu commented Jan 8, 2026

Copy link
Copy Markdown
Collaborator

This is a test PR created to validate picosecond support in the driver.

The following changes were made as part of this validation:

  • Populated the picosecond support parameter timestamp_output_format.
  • Modified several test cases to verify picosecond support.

Create callback:

{
  "kind": "bigquery#queryResponse",
  "schema": {
    "fields": [
      {
        "name": "Id",
        "type": "INTEGER"
      },
      {
        "name": "DOB",
        "type": "TIMESTAMP",
        "timestampPrecision": "12"
      }
    ]
  },
  "jobReference": {
    "projectId": "bigquery-devtools-drivers",
    "jobId": "job_4SU-yFhDwhU6MkF450u8ej0YdMi9",
    "location": "US"
  },
  "totalBytesProcessed": "0",
  "jobComplete": true,
  "cacheHit": false,
  "queryId": "job_4SU-yFhDwhU6MkF450u8ej0YdMi9",
  "jobCreationReason": {
    "code": "REQUESTED"
  },
  "totalBytesBilled": "0",
  "totalSlotMs": "0",
  "location": "US",
  "creationTime": "1770104166525",
  "startTime": "1770104166673",
  "endTime": "1770104166794"
}

Insert Callback:

{
  "kind": "bigquery#job",
  "etag": "+WN6H/c5LVKHpWTtCHQ/fQ==",
  "id": "bigquery-devtools-drivers:US.",
  "selfLink": "https://bigquery.googleapis.com/bigquery/v2/projects/bigquery-devtools-drivers/jobs/?location=US",
  "user_email": "bq-devtools-simba-drivers-test@bigquery-devtools-drivers.iam.gserviceaccount.com",
  "configuration": {
    "query": {
      "query": "INSERT INTO ODBC_TEST_DATASET._ODBC_INSERT_TEST_TIMESTAMP_Picosecond (Id, DOB) VALUES (1, '2024-01-20 10:20:30.123456789123'), (2, '2024-01-20 11:02:33.001212123456'), (3, '2024-01-20 02:20:22.123123123451')",
      "destinationTable": {
        "projectId": "bigquery-devtools-drivers",
        "datasetId": "ODBC_TEST_DATASET",
        "tableId": "_ODBC_INSERT_TEST_TIMESTAMP_Picosecond"
      },
      "priority": "INTERACTIVE",
      "allowLargeResults": false,
      "useQueryCache": true,
      "flattenResults": false,
      "useLegacySql": false,
      "parameterMode": "NAMED",
      "scriptOptions": {
        "statementTimeoutMs": "0",
        "statementByteBudget": "0",
        "keyResultStatement": "LAST"
      }
    },
    "dryRun": true,
    "jobTimeoutMs": "0",
    "jobType": "QUERY"
  },
  "jobReference": {
    "projectId": "bigquery-devtools-drivers",
    "location": "US"
  },
  "statistics": {
    "creationTime": "1770104169194",
    "totalBytesProcessed": "0",
    "query": {
      "totalBytesProcessed": "0",
      "totalBytesBilled": "0",
      "cacheHit": false,
      "referencedTables": [
        {
          "projectId": "bigquery-devtools-drivers",
          "datasetId": "ODBC_TEST_DATASET",
          "tableId": "_ODBC_INSERT_TEST_TIMESTAMP_Picosecond"
        }
      ],
      "schema": {
        "fields": [
          {
            "name": "Id",
            "type": "INTEGER",
            "mode": "NULLABLE"
          },
          {
            "name": "DOB",
            "type": "TIMESTAMP",
            "mode": "NULLABLE",
            "timestampPrecision": "12"
          }
        ]
      },
      "statementType": "INSERT",
      "totalBytesProcessedAccuracy": "PRECISE"
    }
  },
  "status": {
    "state": "DONE"
  },
  "principal_subject": "serviceAccount:bq-devtools-simba-drivers-test@bigquery-devtools-drivers.iam.gserviceaccount.com"
}

Select Callback:

{
  "kind": "bigquery#queryResponse",
  "schema": {
    "fields": [
      {
        "name": "DOB",
        "type": "TIMESTAMP",
        "mode": "NULLABLE",
        "timestampPrecision": "12"
      }
    ]
  },
  "jobReference": {
    "projectId": "bigquery-devtools-drivers",
    "jobId": "job_YoT_4BKWd1-bqB_jKy8GOuSCuUoj",
    "location": "US"
  },
  "totalRows": "3",
  "rows": [
    {
      "f": [
        {
          "v": "2024-01-20T10:20:30.123456789123Z"
        }
      ]
    },
    {
      "f": [
        {
          "v": "2024-01-20T11:02:33.001212123456Z"
        }
      ]
    },
    {
      "f": [
        {
          "v": "2024-01-20T02:20:22.123123123451Z"
        }
      ]
    }
  ],
  "totalBytesProcessed": "72",
  "jobComplete": true,
  "cacheHit": false,
  "queryId": "job_YoT_4BKWd1-bqB_jKy8GOuSCuUoj",
  "jobCreationReason": {
    "code": "REQUESTED"
  },
  "totalBytesBilled": "10485760",
  "totalSlotMs": "212",
  "location": "US",
  "creationTime": "1770104175731",
  "startTime": "1770104175835",
  "endTime": "1770104176177"
}

Drop callback:

{
  "kind": "bigquery#job",
  "etag": "zXlV3b1W4Ca73ps44dWOTw==",
  "id": "bigquery-devtools-drivers:US.",
  "selfLink": "https://bigquery.googleapis.com/bigquery/v2/projects/bigquery-devtools-drivers/jobs/?location=US",
  "user_email": "bq-devtools-simba-drivers-test@bigquery-devtools-drivers.iam.gserviceaccount.com",
  "configuration": {
    "query": {
      "query": "DROP TABLE IF EXISTS ODBC_TEST_DATASET._ODBC_INSERT_TEST_TIMESTAMP_Picosecond",
      "destinationTable": {
        "projectId": "bigquery-devtools-drivers",
        "datasetId": "ODBC_TEST_DATASET",
        "tableId": "_ODBC_INSERT_TEST_TIMESTAMP_Picosecond"
      },
      "priority": "INTERACTIVE",
      "allowLargeResults": false,
      "useQueryCache": true,
      "flattenResults": false,
      "useLegacySql": false,
      "scriptOptions": {
        "statementTimeoutMs": "0",
        "statementByteBudget": "0",
        "keyResultStatement": "LAST"
      }
    },
    "dryRun": true,
    "jobTimeoutMs": "0",
    "jobType": "QUERY"
  },
  "jobReference": {
    "projectId": "bigquery-devtools-drivers",
    "location": "US"
  },
  "statistics": {
    "creationTime": "1770104178721",
    "totalBytesProcessed": "0",
    "query": {
      "totalBytesProcessed": "0",
      "totalBytesBilled": "0",
      "cacheHit": false,
      "statementType": "DROP_TABLE",
      "ddlOperationPerformed": "DROP",
      "ddlTargetTable": {
        "projectId": "bigquery-devtools-drivers",
        "datasetId": "ODBC_TEST_DATASET",
        "tableId": "_ODBC_INSERT_TEST_TIMESTAMP_Picosecond"
      },
      "totalBytesProcessedAccuracy": "PRECISE"
    }
  },
  "status": {
    "state": "DONE"
  },
  "principal_subject": "serviceAccount:bq-devtools-simba-drivers-test@bigquery-devtools-drivers.iam.gserviceaccount.com"
}

Full test-suite run on local:
image

@Khushikathuria008 Khushikathuria008 force-pushed the picosecond_support branch 4 times, most recently from e2fb822 to 589051a Compare January 29, 2026 07:56

void InsertTimestampData(std::shared_ptr<ODBCHandles> const& conn,
std::vector<SQL_TIMESTAMP_STRUCT> rows,
std::vector<std::string> rows,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this modified?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp struct only contains fractions upto 9 digits. We are utilising this func in picoseconds as well.Hence updated it.

<< (row.minute < 10 ? "0" : "") << row.minute << ":"
<< (row.second < 10 ? "0" : "") << row.second << "."
<< row.fraction << "'";
// if (row.year != 0) {

@shivamd-gpartner shivamd-gpartner Feb 2, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are so many of these unnecessary code, remove it if not needed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

std::string insert_stmt_str = insert_stmt.str();
SQLRETURN status;

std::cout << "Insert Timestamp Statement: " << insert_stmt_str << std::endl;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove these prints

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Khushikathuria008 Khushikathuria008 force-pushed the picosecond_support branch 3 times, most recently from 64602a3 to 41805f5 Compare February 3, 2026 05:11
*res_len = kTimestampBinaryLength;
}
timestamp_src_struct.fraction = timestamp_src_struct.fraction * 1000;
timestamp_src_struct.fraction = timestamp_src_struct.fraction;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we removed this 1000 factor here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it was always converting to nanoseconds. even when not needed.

&ts.month, &ts.day, &ts.hour, &ts.minute, &ts.second, &micro);
}

if (matched < 6) {

@shivamd-gpartner shivamd-gpartner Feb 3, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this working? we have duplicate blocks of if condition and if needed see if can be combined

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@shivamd-gpartner

Copy link
Copy Markdown
Collaborator

@Khushikathuria008 also add full test cases output

@Khushikathuria008 Khushikathuria008 force-pushed the picosecond_support branch 4 times, most recently from 5b972cb to 17776b4 Compare February 5, 2026 10:02

DSRow CreateDSRowFromTypeInfo(TypeInfoRow const& type_info) {
bool IsTimeRelated(TypeInfoRow const& type_info) {
return type_info.sql_data_type == SQL_TYPE_TIMESTAMP ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we verified Date also has picoseconds support?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. date doesnt support it.

@shivamd-gpartner shivamd-gpartner marked this pull request as ready for review February 13, 2026 09:55
@shivamd-gpartner shivamd-gpartner requested review from a team and sachinpro February 13, 2026 09:55
@Khushikathuria008 Khushikathuria008 requested a review from a team as a code owner March 16, 2026 10:04
@Khushikathuria008 Khushikathuria008 marked this pull request as draft March 16, 2026 10:12
@Khushikathuria008 Khushikathuria008 removed the request for review from sachinpro March 16, 2026 10:12
@sachinpro

Copy link
Copy Markdown
Collaborator

@Khushikathuria008 Please rebase this branch from main and resolve the merge conflicts.

@sachinpro

Copy link
Copy Markdown
Collaborator

@Khushikathuria008 Can you please refactor this PR to have only the REST flow. Let's get it merged before we get into the HTAPI flow.

@Khushikathuria008 Khushikathuria008 force-pushed the picosecond_support branch 6 times, most recently from 43658b1 to c5cd918 Compare June 11, 2026 05:23
TEST(DataTranslationTest, From_SQL_Timestamp_to_all_picosecond_support) {
auto conn = std::make_shared<ODBCHandles>();
std::string connection_string =
kDefaultConnectionString + ";TimestampOutputFormat=ISO8601_STRING;";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this new param 'TimestampOutputFormat' and why is this needed? don't think there was a requirement for this

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TimestampOutputFormat parameter controls the format in which timestamp values are returned by the driver. To have the driver return timestamps as ISO-8601 strings and preserve picosecond precision, set TimestampOutputFormat=ISO8601_STRING.

@shivamd-gpartner shivamd-gpartner Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can keep a similar bool useFullPrecisionTimestamp true or false instead. @sachinpro can confirm?

status_record =
StatusRecord{SQLStates::k_22003(), "Buffer length is insufficient"};
// --- Check for ISO string with 'T' and long fraction ---
auto t_pos = str_val.find('T');

@shivamd-gpartner shivamd-gpartner Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this logic to another function and document the same

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

std::vector<ConnectionProperty> connection_properties;
std::uint32_t row_fetched_per_block = 100000;
std::uint32_t default_string_column_length = 16384;
google::cloud::bigquery_v2_minimal_internal::DataFormatOptions format_options;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if not needed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its needed for setting the values in DSN.

return status_record;
}

odbc_internal::StatusRecord ConvertTimestampStringToChar(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please write unit test cases as well

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Khushikathuria008 Khushikathuria008 force-pushed the picosecond_support branch 2 times, most recently from 0d1a3ad to c4f7ba0 Compare June 11, 2026 17:48
@shivamd-gpartner shivamd-gpartner marked this pull request as ready for review June 12, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants