Skip to content

feat(spanner): implement search_catalog tool and add docs/tests#3140

Open
anikasharma03 wants to merge 1 commit into
googleapis:mainfrom
anikasharma03:spanner
Open

feat(spanner): implement search_catalog tool and add docs/tests#3140
anikasharma03 wants to merge 1 commit into
googleapis:mainfrom
anikasharma03:spanner

Conversation

@anikasharma03
Copy link
Copy Markdown
Contributor

Description

  • Implements search tool for Spanner assets using Dataplex.
  • Updates Spanner source to handle Dataplex clients with caching and OAuth.
  • Adds prebuilt tool configurations for both GoogleSQL and PostgreSQL dialects.
  • Includes tests and documentation.

PR Checklist

Thank you for opening a Pull Request! Before submitting your PR, there are a
few things you can do to make sure it goes smoothly:

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>

@anikasharma03 anikasharma03 requested review from a team as code owners April 28, 2026 20:28
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the search_catalog tool for Cloud Spanner, enabling searches for data assets in Knowledge Catalog (Dataplex). The changes include the tool implementation, documentation, and updates to the Spanner source to support Dataplex client initialization with OAuth token caching. Review feedback highlights a style guide violation in the documentation title format, suggests improving the ExtractType logic for better LLM context, and identifies a redundant nil check on the search iterator.

@@ -0,0 +1,65 @@
---
title: "spanner-search-catalog"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the repository rules, the title in the YAML frontmatter for tool documentation files should use kebab-case for the tool name, followed by ' Tool'.

Suggested change
title: "spanner-search-catalog"
title: "spanner-search-catalog Tool"
References
  1. For tool documentation files, the title in the YAML frontmatter should use kebab-case for the tool name, followed by ' Tool'.

Comment on lines +172 to +178
func ExtractType(resourceString string) string {
lastIndex := strings.LastIndex(resourceString, "/")
if lastIndex == -1 {
return resourceString
}
return typeMap[resourceString[lastIndex+1:]]
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The ExtractType function returns an empty string if the entry type suffix is not found in the typeMap. This might be confusing for the LLM. It would be better to return the original suffix or a default value like 'UNKNOWN' when a mapping is missing.

func ExtractType(resourceString string) string {
	lastIndex := strings.LastIndex(resourceString, "/")
	if lastIndex == -1 {
		return resourceString
	}
	suffix := resourceString[lastIndex+1:]
	if val, ok := typeMap[suffix]; ok {
		return val
	}
	return suffix
}

Comment on lines +228 to +230
if it == nil {
return nil, util.NewClientServerError(fmt.Sprintf("failed to create search entries iterator for project %q", source.ProjectID()), http.StatusInternalServerError, nil)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The SearchEntries method in the generated Dataplex client returns an iterator and does not return nil. This check is redundant. Errors should be handled during iteration using it.Next().

it := catalogClient.SearchEntries(ctx, req)

@anikasharma03 anikasharma03 force-pushed the spanner branch 6 times, most recently from 8ec782a to 6c6997a Compare May 6, 2026 10:24
@anikasharma03 anikasharma03 requested a review from a team as a code owner May 6, 2026 10:24
Copy link
Copy Markdown

@TanmayVartak TanmayVartak left a comment

Choose a reason for hiding this comment

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

Thanks for adding this functionality to Spanner source.

return s.UseClientOAuth
}

func (s *Source) GetCatalogClient(ctx context.Context, tokenString string) (*dataplexapi.CatalogClient, error) {
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 GetCatalogClient be part of utils shared across multiple data sources? Code is generic and nothing specific to Spanner.

return resourceType
}

func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fix formatting.

DataplexEntry string
}

var typeMap = map[string]string{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apart from typeMap everything in this function is generic and may provide additional opportunity to move generic functionality under util. Consider base class "SearchCatalog(typeMap, )"

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.

3 participants