Skip to content

Refactoring packages and adding some skeletons for ResultSet and Statement - #3

Merged
gopalldb merged 14 commits into
mainfrom
client
Jul 21, 2023
Merged

gopalldb merged 14 commits into
mainfrom
client

Conversation

@gopalldb

@gopalldb gopalldb commented Jul 5, 2023

Copy link
Copy Markdown
Collaborator

No description provided.

return new DBArrowStreamResult(manifest, data);
case JSON_ARRAY:
// This is only for testing and prototype
return new DBInlineJsonResult(manifest, data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you will actually need it for small result?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

How will we identify queries with small results? IIUC, we won't do any parsing of query provided by the customer. Thus for all SQL execution, Arrow stream will be the default format.

I think for metadata queries (if we happen to use SQL queries for that), we can use inline-json.


import java.sql.SQLException;

class DBArrowStreamResult implements IExecutionResult {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you spell out DB to Databricks? Or you can simplify it to ArrawStreamResult since its namespace is evident.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ditto to others.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

ExecuteStatementRequest request = new ExecuteStatementRequest()
.setStatement(statement)
.setWarehouseId(warehouseId)
.setDisposition(Disposition.INLINE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wonder if at the end this will become part of configuration at connection level.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That would depend on what controls we want to provide to our users. And if we want to support multiple formats in full fledged manner. I think for now we will use only Arrow stream for user provided queries.

this.connectionContext = connectionContext;
// Handle more auth types
this.databricksConfig = new DatabricksConfig();
databricksConfig.setHost(connectionContext.getHostUrl());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I miss this pattern
this.databricksConfig = new DatabricksConfig()
.setHost(connectionContext.getHostUrl())
.setToken(connectionContext.getToken());

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done :)

* @param statementId statement which should be closed
* @return response for statement execution
*/
void closeStatement(String statementId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  1. Why not both executeStatement and closeStatement live off "session" or you do not have session object or class?
  2. Which session will be used in closeStatement?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Close statement request takes only the statement-Id. Since a statement is associated uniquely with a session, the underlying session would be used, which I believe would be handled on server side. ExecuteStatement creates the statement, so session-Id is required here, otherwise it would create a new one on backend side.


private int currentRow;
private List<List<String>> data;
private ResultManifest resultManifest;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

resultManifest and resultData are final/readonly?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

if (columnIndex < data.get(currentRow).size()) {
return data.get(currentRow).get(columnIndex);
}
throw new DatabricksSQLException("Column index out of bounds " + (columnIndex -1));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you print the original value of columnIndex (do not tweak the value in the log or exception which can cause confusions).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done


@Override
public synchronized int getCurrentRow() {
return currentRow + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

currentRowis initialized to zero which is current? Do you skip the first row by chance?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, I intended this to be JDBC index, which starts from 1. But I think it is better to use internal index for this class, which starts from 0, and have all those index translations in upper level class.

*/
String columnTypeText();

int typePrecision();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add method doc.
precision is the maximum number of significant digits that can be stored in a column. For string, it's 255.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

import com.databricks.jdbc.core.DatabricksResultSet;
import com.databricks.sdk.service.sql.*;

public class FakeDatabricksClient implements DatabricksClient {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you want to mock the client or mock SQL Exec API?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to mock only StatementExecutionService, but there were some other nuances in WorkspaceClient, so I created a Fake client, which would directly call the statement execution service without going into Workspace client. I think for that, we can keep separate E2E tests, which will cover testing through all layers.

* @return response for statement execution
*/
void closeStatement(String statementId);
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the blank line EOF.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

String getSessionId();

void close(boolean removeFromSession) throws SQLException;
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the blank line EOF.

public void closeStatement(String statementId) {
statementExecutionService.closeStatement(new CloseStatementRequest().setStatementId(statementId));
}
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the blank line EOF.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

@gopalldb
gopalldb merged commit 4dbf472 into main Jul 21, 2023
@gopalldb
gopalldb deleted the client branch July 21, 2023 04:41
gopalldb added a commit to gopalldb/databricks-jdbc that referenced this pull request Apr 23, 2026
- Add comment explaining directResultsReceived timing: the flag checked
  is from the PREVIOUS execution, reset happens below
- Add comment explaining synchronous close latency tradeoff: consistent
  with pgJDBC's closeForNextExecution, correctness over latency
- Expand catch comment to cover transport-level errors
- Add testReExecutionHandlesTransportErrorGracefully: verifies
  re-execution succeeds even when closeStatement throws a RuntimeException
  (transport-level error like HTTP 500), not just DatabricksSQLException

Note on integration test gap (databricks#3): the existing mock-based tests verify
the close is called. Transport-level regression requires a real Thrift
endpoint — tracked as a follow-up with the fake service infrastructure.

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
gopalldb added a commit that referenced this pull request May 11, 2026
Major fixes:
- #1: Use 2-thread pool instead of single-thread to prevent one blocked
  heartbeat RPC from starving others on the same connection
- #3: Fix getStoppedFlag() leak — use get() + ALREADY_STOPPED sentinel
  instead of computeIfAbsent() which re-created a false flag after
  stopHeartbeat() removed it, causing RPCs after stop

Minor fixes:
- #2: Increase awaitTermination from 5s to 10s with explanatory comment
- #4: Add comment about client capture retaining session reference
- #5: Document reactive vs proactive heartbeat stop limitation
- #6, #7, #9, #10, #11: Acknowledged as correct/acceptable per reviewer

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
vikrantpuppala added a commit that referenced this pull request May 20, 2026
Removes the OWASP step, NVD database cache, and OWASP findings parsing
from securityScan.yml. OSV-Scanner now drives the gate alone.

Motivation:

  - OSV's database is a strict superset of NVD's (federates GHSA, NVD,
    PyPA, RustSec, Go vuln DB). We've already seen two real CVEs OSV
    catches that OWASP misses entirely -- CVE-2025-66566 in lz4 and
    CVE-2026-5598 in bouncycastle, both GHSA-only with no NVD CPE.

  - The release pipeline at databricks/secure-public-registry-releases-eng
    already skips OWASP (every Maven step has -Ddependency-check.skip=true)
    and runs its own artifact-level scan via databricks/gh-action-scan.
    So removing OWASP from this repo's CI does not disturb release gating.

  - OWASP's NVD database (~150-700 MB), the NVD_API_KEY secret, and the
    cache machinery added minutes per run for coverage we don't actually
    use any more.

The OWASP plugin block stays in jdbc-core/pom.xml and owasp-suppressions.xml
stays in the repo, because the disabled-anyway in-repo release.yml /
release-thin.yml workflows still reference them. Cleaning those up is a
separate change.

Also addresses these from the PR review:

  #1 (SBOM existence guard): the OSV step now explicitly checks
      target/bom.json exists before scanning, and that osv-scanner
      produced a non-empty output. Build failures now surface with a
      clear ::error:: instead of a downstream jq error.

  #3 (set -uo pipefail without -e): added a comment explaining that -e
      is dropped intentionally because osv-scanner exits 1 on any
      finding regardless of severity; the severity >= 7 filter below is
      the real gate.

  #4 (severity filter silently treats malformed scores as 0): the
      Collect findings step now logs total_findings alongside
      high_count, so a mismatch (e.g. "10 total / 0 high") would be
      visible in the step summary and warn ops about OSV format drift.

  #5 (suppressions are CVE-id global, not package-scoped): OSV-Scanner
      v2.3.8 does not actually support per-package CVE-id ignores
      (verified against internal/config/config.go -- PackageOverrides
      has no per-CVE field). Documented the trade-off explicitly in
      osv-scanner.toml's header so future readers understand the
      scoping model and the acceptable-risk reasoning.

  #7 (fork PR maven config): added a comment in the workflow explaining
      that fork PRs work even with JFrog OIDC skipped, because all of
      the driver's direct dependencies are published to public Maven
      Central. JFrog is just a mirror, not a source.

Verified locally: OSV reports the same 2 unsuppressed CVSS>=7 findings
(bouncycastle CVE-2026-5598 + libthrift cluster) as before, with no
schema errors against the corrected osv-scanner.toml.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <[email protected]>
vikrantpuppala added a commit that referenced this pull request May 21, 2026
Removes the OWASP step, NVD database cache, and OWASP findings parsing
from securityScan.yml. OSV-Scanner now drives the gate alone.

Motivation:

  - OSV's database is a strict superset of NVD's (federates GHSA, NVD,
    PyPA, RustSec, Go vuln DB). We've already seen two real CVEs OSV
    catches that OWASP misses entirely -- CVE-2025-66566 in lz4 and
    CVE-2026-5598 in bouncycastle, both GHSA-only with no NVD CPE.

  - The release pipeline at databricks/secure-public-registry-releases-eng
    already skips OWASP (every Maven step has -Ddependency-check.skip=true)
    and runs its own artifact-level scan via databricks/gh-action-scan.
    So removing OWASP from this repo's CI does not disturb release gating.

  - OWASP's NVD database (~150-700 MB), the NVD_API_KEY secret, and the
    cache machinery added minutes per run for coverage we don't actually
    use any more.

The OWASP plugin block stays in jdbc-core/pom.xml and owasp-suppressions.xml
stays in the repo, because the disabled-anyway in-repo release.yml /
release-thin.yml workflows still reference them. Cleaning those up is a
separate change.

Also addresses these from the PR review:

  #1 (SBOM existence guard): the OSV step now explicitly checks
      target/bom.json exists before scanning, and that osv-scanner
      produced a non-empty output. Build failures now surface with a
      clear ::error:: instead of a downstream jq error.

  #3 (set -uo pipefail without -e): added a comment explaining that -e
      is dropped intentionally because osv-scanner exits 1 on any
      finding regardless of severity; the severity >= 7 filter below is
      the real gate.

  #4 (severity filter silently treats malformed scores as 0): the
      Collect findings step now logs total_findings alongside
      high_count, so a mismatch (e.g. "10 total / 0 high") would be
      visible in the step summary and warn ops about OSV format drift.

  #5 (suppressions are CVE-id global, not package-scoped): OSV-Scanner
      v2.3.8 does not actually support per-package CVE-id ignores
      (verified against internal/config/config.go -- PackageOverrides
      has no per-CVE field). Documented the trade-off explicitly in
      osv-scanner.toml's header so future readers understand the
      scoping model and the acceptable-risk reasoning.

  #7 (fork PR maven config): added a comment in the workflow explaining
      that fork PRs work even with JFrog OIDC skipped, because all of
      the driver's direct dependencies are published to public Maven
      Central. JFrog is just a mirror, not a source.

Verified locally: OSV reports the same 2 unsuppressed CVSS>=7 findings
(bouncycastle CVE-2026-5598 + libthrift cluster) as before, with no
schema errors against the corrected osv-scanner.toml.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <[email protected]>
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.

2 participants