Skip to content
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

Add custom connector docs #328

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

GovindHede
Copy link

@GovindHede GovindHede commented Aug 6, 2024

Using Custom Connectors in PyAirbyte

This guide provides detailed instructions for creating and using custom connectors in PyAirbyte. Learn how to define source and destination connectors, implement necessary methods, test your connector, and integrate it with PyAirbyte. This documentation is essential for extending PyAirbyte’s capabilities by adding support for new data sources and destinations.

For additional details and examples, refer to the notebook.

Issue

-91

Copy link

coderabbitai bot commented Aug 6, 2024

Walkthrough

Walkthrough

The recent changes significantly enhance the schema compatibility checks in the Airbyte codebase. Notably, the _ensure_compatible_table_schema method was refactored to include thorough column size compatibility checks and streamline the process of adjusting table schemas. Additionally, comprehensive documentation on creating custom connectors in PyAirbyte was introduced, providing developers with essential guidance for extending the platform's capabilities.

Changes

Files Change Summary
airbyte/_future_cdk/sql_processor.py Expanded _ensure_compatible_table_schema to include column size checks and added new private methods for schema retrieval and alterations.
docs/custom_connectors.md Introduced documentation on creating custom connectors, detailing the process, prerequisites, implementation, and testing practices.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SqlProcessor
    participant Database

    User->>SqlProcessor: Request schema compatibility check
    SqlProcessor->>Database: Retrieve existing table schema
    SqlProcessor->>SqlProcessor: Get stream schema
    SqlProcessor->>SqlProcessor: Check for missing columns
    SqlProcessor->>SqlProcessor: Compare column specifications
    alt Size discrepancies found
        SqlProcessor->>SqlProcessor: Collect alterations
        SqlProcessor->>Database: Execute alterations
    end
    SqlProcessor->>User: Return compatibility status
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 821c699 and 17884ac.

Files selected for processing (2)
  • airbyte/_future_cdk/sql_processor.py (2 hunks)
  • docs/custom_connectors.md (1 hunks)
Additional context used
Markdownlint
docs/custom_connectors.md

22-22: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

Ruff
airbyte/_future_cdk/sql_processor.py

447-447: Line too long (119 > 100)

(E501)


453-458: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


455-455: Blank line contains whitespace

Remove whitespace from blank line

(W293)


457-457: Line too long (111 > 100)

(E501)


463-468: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


465-465: Blank line contains whitespace

Remove whitespace from blank line

(W293)


467-467: Line too long (107 > 100)

(E501)


474-474: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


478-484: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


480-480: Blank line contains whitespace

Remove whitespace from blank line

(W293)


485-485: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


486-486: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


487-487: Blank line contains whitespace

Remove whitespace from blank line

(W293)


488-488: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


488-488: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


489-489: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


489-489: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


490-490: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


490-490: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


494-494: Line too long (108 > 100)

(E501)


495-502: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


497-497: Blank line contains whitespace

Remove whitespace from blank line

(W293)


503-503: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


507-511: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


509-509: Blank line contains whitespace

Remove whitespace from blank line

(W293)

Additional comments not posted (7)
docs/custom_connectors.md (7)

6-8: LGTM!

The overview section is clear and concise.


10-16: LGTM!

The prerequisites section is clear and provides necessary information.


18-39: LGTM!

The section on defining a custom connector is clear and provides a useful example.

Tools
Markdownlint

22-22: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


41-45: LGTM!

The section on implementing required methods is clear and provides necessary information.


47-51: LGTM!

The section on testing your custom connector is clear and provides necessary information.


52-62: LGTM!

The section on integrating with PyAirbyte is clear and provides a useful example.


64-66: LGTM!

The section on additional resources is clear and provides useful links.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

if column_name in existing_schema:
existing_column_spec = existing_schema[column_name]
if self._is_size_expansion_needed(existing_column_spec, new_column_spec):
alterations.append(self._generate_alter_column_statement(table_name, column_name, new_column_spec))
Copy link

Choose a reason for hiding this comment

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

Address the long line.

The line exceeds the maximum line length of 100 characters.

-                    alterations.append(self._generate_alter_column_statement(table_name, column_name, new_column_spec))
+                    alterations.append(
+                        self._generate_alter_column_statement(
+                            table_name, column_name, new_column_spec
+                        )
+                    )
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
alterations.append(self._generate_alter_column_statement(table_name, column_name, new_column_spec))
alterations.append(
self._generate_alter_column_statement(
table_name, column_name, new_column_spec
)
)
Tools
Ruff

447-447: Line too long (119 > 100)

(E501)

Comment on lines +453 to +458
"""
Retrieve the schema for the specified stream.

:param stream_name: Name of the stream
:return: Dictionary of the stream's schema with column names as keys and their specifications as values
"""
Copy link

Choose a reason for hiding this comment

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

Improve docstring formatting.

The multi-line docstring summary should start at the first line and remove whitespace after opening quotes.

-        """
-    
+        """Retrieve the schema for the specified stream.
+
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""
Retrieve the schema for the specified stream.
:param stream_name: Name of the stream
:return: Dictionary of the stream's schema with column names as keys and their specifications as values
"""
"""Retrieve the schema for the specified stream.
:param stream_name: Name of the stream
:return: Dictionary of the stream's schema with column names as keys and their specifications as values
"""
Tools
Ruff

453-458: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


455-455: Blank line contains whitespace

Remove whitespace from blank line

(W293)


457-457: Line too long (111 > 100)

(E501)

Comment on lines +495 to +504
"""
Generate an ALTER TABLE statement for expanding column size.

:param table_name: Name of the table
:param column_name: Name of the column
:param column_spec: New column specification
:return: ALTER TABLE statement as a string
"""
new_type = column_spec['Type']
return f"ALTER TABLE {table_name} MODIFY {column_name} {new_type}"
Copy link

Choose a reason for hiding this comment

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

Improve docstring formatting.

The multi-line docstring summary should start at the first line and remove whitespace after opening quotes.

-        """
-    
+        """Generate an ALTER TABLE statement for expanding column size.
+
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""
Generate an ALTER TABLE statement for expanding column size.
:param table_name: Name of the table
:param column_name: Name of the column
:param column_spec: New column specification
:return: ALTER TABLE statement as a string
"""
new_type = column_spec['Type']
return f"ALTER TABLE {table_name} MODIFY {column_name} {new_type}"
"""Generate an ALTER TABLE statement for expanding column size.
:param table_name: Name of the table
:param column_name: Name of the column
:param column_spec: New column specification
:return: ALTER TABLE statement as a string
"""
new_type = column_spec['Type']
return f"ALTER TABLE {table_name} MODIFY {column_name} {new_type}"
Tools
Ruff

495-502: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


497-497: Blank line contains whitespace

Remove whitespace from blank line

(W293)


503-503: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

Comment on lines +478 to +492
"""
Check if the column size needs to be expanded.

:param existing_spec: Specification of the existing column
:param new_spec: Specification of the new column
:return: True if size expansion is needed, False otherwise
"""
existing_type = existing_spec['Type']
new_type = new_spec['Type']

if '(' in existing_type and '(' in new_type:
existing_size = int(existing_type.split('(')[1].rstrip(')'))
new_size = int(new_type.split('(')[1].rstrip(')'))
return new_size > existing_size
return False
Copy link

Choose a reason for hiding this comment

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

Improve docstring formatting and use double quotes.

The multi-line docstring summary should start at the first line, remove whitespace after opening quotes, and replace single quotes with double quotes.

-        """
-    
+        """Check if the column size needs to be expanded.
+
-        existing_type = existing_spec['Type']
-        new_type = new_spec['Type']
+        existing_type = existing_spec["Type"]
+        new_type = new_spec["Type"]
-        if '(' in existing_type and '(' in new_type:
-            existing_size = int(existing_type.split('(')[1].rstrip(')'))
-            new_size = int(new_type.split('(')[1].rstrip(')'))
+        if "(" in existing_type and "(" in new_type:
+            existing_size = int(existing_type.split("(")[1].rstrip(")"))
+            new_size = int(new_type.split("(")[1].rstrip(")"))
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""
Check if the column size needs to be expanded.
:param existing_spec: Specification of the existing column
:param new_spec: Specification of the new column
:return: True if size expansion is needed, False otherwise
"""
existing_type = existing_spec['Type']
new_type = new_spec['Type']
if '(' in existing_type and '(' in new_type:
existing_size = int(existing_type.split('(')[1].rstrip(')'))
new_size = int(new_type.split('(')[1].rstrip(')'))
return new_size > existing_size
return False
"""Check if the column size needs to be expanded.
:param existing_spec: Specification of the existing column
:param new_spec: Specification of the new column
:return: True if size expansion is needed, False otherwise
"""
existing_type = existing_spec["Type"]
new_type = new_spec["Type"]
if "(" in existing_type and "(" in new_type:
existing_size = int(existing_type.split("(")[1].rstrip(")"))
new_size = int(new_type.split("(")[1].rstrip(")"))
return new_size > existing_size
return False
Tools
Ruff

478-484: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


480-480: Blank line contains whitespace

Remove whitespace from blank line

(W293)


485-485: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


486-486: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


487-487: Blank line contains whitespace

Remove whitespace from blank line

(W293)


488-488: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


488-488: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


489-489: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


489-489: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


490-490: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)


490-490: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

Comment on lines +507 to +515
"""
Execute a list of ALTER TABLE statements.

:param alterations: List of ALTER TABLE statements
"""
with self.get_sql_connection() as conn:
for alter_statement in alterations:
conn.execute(alter_statement)

Copy link

Choose a reason for hiding this comment

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

Improve docstring formatting.

The multi-line docstring summary should start at the first line and remove whitespace after opening quotes.

-        """
-    
+        """Execute a list of ALTER TABLE statements.
+
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""
Execute a list of ALTER TABLE statements.
:param alterations: List of ALTER TABLE statements
"""
with self.get_sql_connection() as conn:
for alter_statement in alterations:
conn.execute(alter_statement)
"""Execute a list of ALTER TABLE statements.
:param alterations: List of ALTER TABLE statements
"""
with self.get_sql_connection() as conn:
for alter_statement in alterations:
conn.execute(alter_statement)
Tools
Ruff

507-511: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


509-509: Blank line contains whitespace

Remove whitespace from blank line

(W293)

Comment on lines +463 to +475
"""
Retrieve the schema of the specified table.

:param table_name: Name of the table
:return: Dictionary of existing schema with column names as keys and their specifications as values
"""
query = f"DESCRIBE {table_name}"
with self.get_sql_connection() as conn:
result = conn.execute(query).fetchall()
schema = {}
for row in result:
schema[row['Field']] = row
return schema
Copy link

Choose a reason for hiding this comment

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

Improve docstring formatting and use double quotes.

The multi-line docstring summary should start at the first line, remove whitespace after opening quotes, and replace single quotes with double quotes.

-        """
-    
+        """Retrieve the schema of the specified table.
+
-        query = f"DESCRIBE {table_name}"
+        query = f'DESCRIBE {table_name}'
-            schema[row['Field']] = row
+            schema[row["Field"]] = row
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""
Retrieve the schema of the specified table.
:param table_name: Name of the table
:return: Dictionary of existing schema with column names as keys and their specifications as values
"""
query = f"DESCRIBE {table_name}"
with self.get_sql_connection() as conn:
result = conn.execute(query).fetchall()
schema = {}
for row in result:
schema[row['Field']] = row
return schema
"""Retrieve the schema of the specified table.
:param table_name: Name of the table
:return: Dictionary of existing schema with column names as keys and their specifications as values
"""
query = f'DESCRIBE {table_name}'
with self.get_sql_connection() as conn:
result = conn.execute(query).fetchall()
schema = {}
for row in result:
schema[row["Field"]] = row
return schema
Tools
Ruff

463-468: Multi-line docstring summary should start at the first line

Remove whitespace after opening quotes

(D212)


465-465: Blank line contains whitespace

Remove whitespace from blank line

(W293)


467-467: Line too long (107 > 100)

(E501)


474-474: Single quotes found but double quotes preferred

Replace single quotes with double quotes

(Q000)

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.

1 participant