The error raises from the double quote " in string...
# replication-ask-ai
h
The error raises from the double quote " in string wraping the value "1.00".
Copy code
ERROR type-and-dedupe i.a.i.b.d.t.TypeAndDedupeTransaction(executeTypeAndDedupe):48 Encountered Exception on unsafe SQL for stream INV SOAllocation with suffix , attempting with error handling org.postgresql.util.PSQLException: ERROR: invalid input syntax for type numeric: ""1.00""
I go deep in db query, could see this:
Copy code
CASE WHEN (
	"_airbyte_data" -> 'Qty' is not null and JSONB_TYPEOF("_airbyte_data" -> 'Qty') <> 'null' 
	and "pg_temp"."airbyte_safe_cast"(
		case when (
			"_airbyte_data" -> 'Qty' is null or 
			JSONB_TYPEOF("_airbyte_data" -> 'Qty') = 'null') 
			then null 
			else cast("_airbyte_data" -> 'Qty' as varchar) 
		end, 
		cast(null as decimal(38, 9))
	) is null
	) 
THEN JSONB_BUILD_OBJECT('field', 'Qty', 'change', 'NULLED', 'reason', 'DESTINATION_TYPECAST_ERROR') 
ELSE cast(null as jsonb) 
END
Note: Airbyte setting these fields to
null
only happens on subsequent incremental syncs.
k
The error you're encountering,
invalid input syntax for type numeric: ""1.00""
, suggests that there is an issue with the way the value
"1.00"
is being cast or handled in your SQL query. Specifically, the double quotes around the value are causing the problem. From the provided information, it seems that the error occurs during the normalization step when Airbyte attempts to cast JSONB data to a numeric type. The relevant part of the query is:
Copy code
sql CASE WHEN (  "_airbyte_data" -> 'Qty' is not null and JSONB_TYPEOF("_airbyte_data" -> 'Qty') <> 'null'   and "pg_temp"."airbyte_safe_cast"(   case when (    "_airbyte_data" -> 'Qty' is null or     JSONB_TYPEOF("_airbyte_data" -> 'Qty') = 'null')     then null     else cast("_airbyte_data" -> 'Qty' as varchar)    end,    cast(null as decimal(38, 9))  ) is null  )  THEN JSONB_BUILD_OBJECT('field', 'Qty', 'change', 'NULLED', 'reason', 'DESTINATION_TYPECAST_ERROR')  ELSE cast(null as jsonb)  END
### Steps to Resolve 1. Check the Source Data: Ensure that the source data does not contain extra double quotes around numeric values. The value should be a valid numeric type without additional quotes. 2. Modify the SQL Query: Adjust the SQL query to handle cases where the value might be improperly quoted. You can use string functions to remove any extraneous quotes before casting. 3. Update Airbyte Version: Ensure you are using the latest version of Airbyte, as there might be fixes or improvements related to data type handling in newer versions. ### Example Adjustment You might need to adjust the SQL query to strip out any extra quotes before attempting to cast the value. Here is an example of how you might modify the query:
Copy code
sql CASE WHEN (  "_airbyte_data" -> 'Qty' is not null and JSONB_TYPEOF("_airbyte_data" -> 'Qty') <> 'null'   and "pg_temp"."airbyte_safe_cast"(   case when (    "_airbyte_data" -> 'Qty' is null or     JSONB_TYPEOF("_airbyte_data" -> 'Qty') = 'null')     then null     else cast(regexp_replace(cast("_airbyte_data" -> 'Qty' as varchar), '["]', '', 'g') as varchar)    end,    cast(null as decimal(38, 9))  ) is null  )  THEN JSONB_BUILD_OBJECT('field', 'Qty', 'change', 'NULLED', 'reason', 'DESTINATION_TYPECAST_ERROR')  ELSE cast(null as jsonb)  END
In this example,
regexp_replace
is used to remove any double quotes from the value before casting it to a numeric type. ### Additional Resources For more detailed guidance, you can refer to the [Airbyte documentation](https://docs.airbyte.com) or seek further assistance on the [Airbyte community forum](https://discuss.airbyte.io). If you continue to experience issues, please provide additional details or logs to help diagnose the problem further.
h
@kapa.ai Yes, the problem maybe from the Source Data. Airbyte only wrap these fields with double quotes on subsequent incremental syncs, my source is mssql server.
k
It seems like you are experiencing an issue where Airbyte wraps fields with double quotes during incremental syncs from an MSSQL source. This behavior can be related to how Airbyte handles data types and formats during the sync process. Based on the information from the knowledge sources, here are a few points that might be relevant to your situation: 1. Datetimeoffset Parsing Issue: - There is a known issue with parsing
datetimeoffset
fields in MSSQL during incremental syncs. This can cause failures if the datetime format is not correctly parsed. - Example error:
Copy code
java.time.format.DateTimeParseException: Text '2022-11-14 21:20:06.446667 +00:00' could not be parsed at index 19
- [Source](https://github.com/airbytehq/airbyte/issues/32780) 2. Incremental Sync Behavior: - When using the incremental append option, Airbyte might treat updates or deletions as new inserts, which could lead to unexpected behavior in the target database. - If you need to update existing records, you might need to use the incremental + dedup option, but this is only available for certain destinations. - [Source](https://github.com/airbytehq/airbyte/issues/33242) 3. CSV Metadata Wrapping: - There is an issue where the S3 destination connector wraps metadata columns in double quotes during syncs. This might be similar to what you are experiencing with MSSQL. - Example:
Copy code
"_airbyte_ab_id","_airbyte_emitted_at","_airbyte_data"      "465e901d-739a-4568-a5af-0567496034e8",1709812731552,"{"id":"1","first_name":"Michael","last_name":"Perez","email":"<mailto:mperez0@chronoengine.com|mperez0@chronoengine.com>"}"
- [Source](https://github.com/airbytehq/airbyte/issues/35957) Given these points, here are some actionable steps you can take: 1. Check Data Types: - Ensure that the data types in your MSSQL source are compatible with Airbyte's expected formats. Pay special attention to
datetimeoffset
fields. 2. Review Sync Options: - If you are using incremental append and facing issues with updates, consider if your destination supports incremental + dedup and switch to that if possible. 3. Update Airbyte Version: - Make sure you are using the latest version of Airbyte and the connectors, as there might be fixes for these issues in newer releases. If these steps do not resolve your issue, you might want to provide more specific details or logs to the Airbyte community or support team for further assistance.
h
@kapa.ai How can I change the query and apply to the process? I use the OSS version.
k
A message from kapa.ai
A message from kapa.ai
To change the query and apply it to the process in Airbyte Open Source, you can follow the steps outlined in the documentation for setting up specific connectors. Here are the steps for two common sources: Datadog and Google Ads. ### For Datadog 1. Navigate to the Airbyte Open Source dashboard. 2. Set the name for your source. 3. Enter your
api_key
- Datadog API key. 4. Enter your
application_key
- Datadog application key. 5. Enter your
query
- Optional. Type your query to filter records when collecting data from Logs and AuditLogs stream. 6. Enter your
limit
- Number of records to collect per request. 7. Enter your
start_date
- Optional. Start date to filter records when collecting data from Logs and AuditLogs stream. 8. Enter your
end_date
- Optional. End date to filter records when collecting data from Logs and AuditLogs stream. 9. Enter your
queries
- Optional. Multiple queries resulting in multiple streams. 1. Enter the
name
- Required. Query Name. 2. Select the
data_source
- Required. Supported data sources - metrics, cloud_cost, logs, rum. 3. Enter the
query
- Required. A classic query string. Example:
Copy code
plaintext
      "kubernetes_state.node.count{*}"
      "@type:resource @resource.status_code:>=400 @resource.type:(xhr OR fetch)"
10. Click
Set up source
.
For more details, refer to the [Datadog Source Setup Guide](https://docs.airbyte.com/integrations/sources/datadog#for-airbyte-oss). ### For Google Ads 1. Log in to your Airbyte Open Source account. 2. In the left navigation bar, click
Sources
. In the top-right corner, click
+ New source
.
3. Find and select
Google Ads
from the list of available sources.
4. Enter a
Source name
of your choosing.
5. Enter the
Developer Token
you obtained from Google.
6. To authenticate your Google account, enter your Google application's
Client ID
,
Client Secret
,
Refresh Token
, and optionally, the
Access Token
.
7. (Optional) Enter a comma-separated list of the
Customer ID(s)
for your account. These IDs are 10-digit numbers that uniquely identify your account.
8. (Optional) Enter customer statuses to filter customers. 9. (Optional) Enter a
Start Date
using the provided datepicker, or by programmatically entering the date in YYYY-MM-DD format.
10. (Optional) You can use the
Custom GAQL Queries
field to enter a custom query using Google Ads Query Language. Click
Add
and enter your query, as well as the desired name of the table for this data in the destination. Multiple queries can be provided.
For more details, refer to the [Google Ads Source Setup Guide](https://docs.airbyte.com/integrations/sources/google-ads#for-airbyte-open-source). ### General Steps for Custom Queries If you are using a different source or need to apply custom queries, the general steps are:
To change the query and apply it to the process in Airbyte Open Source, you can follow the steps outlined in the documentation for setting up specific connectors. Here are the steps for two common sources: Datadog and Google Ads. ### For Datadog 1. Navigate to the Airbyte Open Source dashboard. 2. Set the name for your source. 3. Enter your
api_key
- Datadog API key. 4. Enter your
application_key
- Datadog application key. 5. Enter your
query
- Optional. Type your query to filter records when collecting data from Logs and AuditLogs stream. 6. Enter your
limit
- Number of records to collect per request. 7. Enter your
start_date
- Optional. Start date to filter records when collecting data from Logs and AuditLogs stream. 8. Enter your
end_date
- Optional. End date to filter records when collecting data from Logs and AuditLogs stream. 9. Enter your
queries
- Optional. Multiple queries resulting in multiple streams. 1. Enter the
name
- Required. Query Name. 2. Select the
data_source
- Required. Supported data sources - metrics, cloud_cost, logs, rum. 3. Enter the
query
- Required. A classic query string. Example:
Copy code
plaintext       "kubernetes_state.node.count{*}"       "@type:resource @resource.status_code:>=400 @resource.type:(xhr OR fetch)"
10. Click
Set up source
.
For more details, refer to the [Datadog Source Setup Guide](https://docs.airbyte.com/integrations/sources/datadog#for-airbyte-oss). ### For Google Ads 1. Log in to your Airbyte Open Source account. 2. In the left navigation bar, click
Sources
. In the top-right corner, click
+ New source
.
3. Find and select
Google Ads
from the list of available sources.
4. Enter a
Source name
of your choosing.
5. Enter the
Developer Token
you obtained from Google.
6. To authenticate your Google account, enter your Google application's
Client ID
,
Client Secret
,
Refresh Token
, and optionally, the
Access Token
.
7. (Optional) Enter a comma-separated list of the
Customer ID(s)
for your account. These IDs are 10-digit numbers that uniquely identify your account.
8. (Optional) Enter customer statuses to filter customers. 9. (Optional) Enter a
Start Date
using the provided datepicker, or by programmatically entering the date in YYYY-MM-DD format.
10. (Optional) You can use the
Custom GAQL Queries
field to enter a custom query using Google Ads Query Language. Click
Add
and enter your query, as well as the desired name of the table for this data in the destination. Multiple queries can be provided.
For more details, refer to the [Google Ads Source Setup Guide](https://docs.airbyte.com/integrations/sources/google-ads#for-airbyte-open-source). ### General Steps for Custom Queries If you are using a different source or need to apply custom queries, the general steps are: 1. Access the Airbyte Open Source dashboard. 2. Select the source you want to configure. 3. Look for fields where you can enter custom queries or filters. 4. Enter your custom query in the provided field. 5. **Save or set
To change the query and apply it to the process in Airbyte Open Source (OSS), you can follow these steps: ### Step 1: Customize the SQL Query 1. Export the SQL Files: - You can export the plain SQL files generated by Airbyte. This allows you to customize the queries as needed. - [Source](https://docs.airbyte.com/operator-guides/transformation-and-normalization/transformations-with-sql#customize-sql-query) 2. Edit the SQL Files: - Open the exported SQL files in your preferred SQL editor or tool. - Customize the queries as needed. For example, you can rename columns, tweak column data types, add deduplication logic, or create views instead of tables. - Example customizations:
Copy code
sql      -- Rename columns      SELECT         column1 AS new_column1,        column2 AS new_column2      FROM         your_table;       -- Change data type      SELECT         CAST(column1 AS INTEGER) AS column1,        column2      FROM         your_table;       -- Add deduplication logic      SELECT         DISTINCT ON (primary_key_column) *      FROM         your_table;
### Step 2: Apply the Custom Query 1. Save the Edited SQL Files: - After making the necessary changes, save the edited SQL files. 2. Re-import the SQL Files: - If you are using Docker, you can copy the edited SQL files back into the Docker container where Airbyte is running. - Example command to copy files into a Docker container:
Copy code
sh      docker cp /path/to/your/edited_sql_file.sql airbyte_container_name:/path/inside/container/
3. Restart the Airbyte Services: - Restart the Airbyte services to apply the changes. - Example command to restart Docker containers:
Copy code
sh      docker-compose restart
### Additional Notes - Custom Transformations: - Note that custom transformations using dbt are not available for Airbyte Open Source. This feature is only available in Airbyte Cloud. - [Source](https://docs.airbyte.com/using-airbyte/core-concepts#custom-transformations) - Query Customization for Specific Connectors: - Some connectors, like Datadog and Google Ads, allow you to enter custom queries directly in the Airbyte UI during the setup process. - For Datadog: - You can enter your query to filter records when collecting data from Logs and AuditLogs stream. - [Source](https://docs.airbyte.com/integrations/sources/datadog#for-airbyte-oss) - For Google Ads: - You can use the Custom GAQL Queries field to enter a custom query using Google Ads Query Language. - [Source](https://docs.airbyte.com/integrations/sources/google-ads#for-airbyte-open-source) By following these steps, you can customize and apply your SQL queries in Airbyte OSS. If you encounter any issues or need further assistance, consider reaching out to the Airbyte community or support team.