You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "juarezr (via GitHub)" <gi...@apache.org> on 2025/10/29 20:45:57 UTC
[PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
juarezr opened a new pull request, #57514:
URL: https://github.com/apache/airflow/pull/57514
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #57461
related: #29902
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
# Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean closes #57461
## Summary
Fixes `ArrowTypeError: Expected bytes, got a 'bool' object` when exporting MSSQL bit fields to Parquet format using `MSSQLToGCSOperator`.
### Issue
- Issue: #57461
- Problem: The `MSSQLToGCSOperator` incorrectly mapped MSSQL bit fields (type 2) to `"BOOLEAN"` in the `type_map`, but the base class `BaseSQLToGCSOperator._convert_parquet_schema()` expects `"BOOL"` for boolean types.
### Root Cause
The `type_map` property in `MSSQLToGCSOperator` had an incorrect type mapping:
- **Before**: `type_map = {2: "BOOLEAN", ...}`
- **After**: `type_map = {2: "BOOL", ...}`
This mismatch caused PyArrow schema conversion to fail when processing bit fields in Parquet format exports.
### Impact
- **Affected Users**: Users exporting MSSQL bit fields to Parquet format using `MSSQLToGCSOperator`
- **Breaking Changes**: None (this is a bug fix)
- **Other Export Formats**: CSV and JSON formats are unaffected (they don't use this type mapping)
### Related Issues/PRs
closes: #57461
related: #29902 #11874
### Additional Notes
Users can temporarily work around this issue by creating a custom operator that overrides the `type_map` property:
```python
class FixedMSSQLToGCSOperator(MSSQLToGCSOperator):
type_map = {2: "BOOL", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
```
However, this fix makes the workaround unnecessary.
## Changes Made
### 1. Fixed Type Mapping (`mssql_to_gcs.py`)
- Changed `type_map` from `{2: "BOOLEAN"}` to `{2: "BOOL"}` to match the expected type key in `BaseSQLToGCSOperator._convert_parquet_schema()`
### 2. Updated Tests (`test_mssql_to_gcs.py`)
- Updated `SCHEMA_JSON` and `SCHEMA_JSON_BIT_FIELDS` constants to use `"BOOL"` instead of `"BOOLEAN"` to match the fix
- Added new test `test_exec_success_parquet_with_bit_fields()` to verify that bit fields can be exported to Parquet format without errors
### Files Changed
1. `providers/google/src/airflow/providers/google/cloud/transfers/mssql_to_gcs.py` (line 70)
- Changed `type_map = {2: "BOOLEAN", ...}` to `type_map = {2: "BOOL", ...}`
2. `providers/google/tests/unit/google/cloud/transfers/test_mssql_to_gcs.py`
- Updated schema constants to use `"BOOL"` instead of `"BOOLEAN"`
- Added `test_exec_success_parquet_with_bit_fields()` test
## Testing
The fix has been tested and verified:
- ✅ Tested manually with a DAG exporting MSSQL bit fields to Parquet format
- ✅ Unit tests updated to reflect the correct type mapping
- ✅ New test case added to prevent regression
Command to test the changes:
```sh
$ breeze testing providers-tests --skip-db-tests providers/google/tests/unit/google/cloud/transfers/test_mssql_to_gcs.py
...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "juarezr (via GitHub)" <gi...@apache.org>.
juarezr commented on code in PR #57514:
URL: https://github.com/apache/airflow/pull/57514#discussion_r2484935572
##########
providers/google/src/airflow/providers/google/cloud/transfers/mssql_to_gcs.py:
##########
@@ -67,7 +67,7 @@ class MSSQLToGCSOperator(BaseSQLToGCSOperator):
ui_color = "#e0a98c"
- type_map = {2: "BOOLEAN", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
+ type_map = {2: "BOOL", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
Review Comment:
## Testing results bit_fields
After your advice, I have tested exporting a simple query in the formats PARQUET, CSV, and JSON.
The export process worked fine for all three formats.
I also looked into the source code and found other places that could present the same issue. Please see below for details.
### Results
Query:
```sql
SELECT id, name, isactive, clientid FROM dbo.DriverGroup WHERE id IN (9, 47, 83)
```
This is what was exported to CSV:
```csv
id,name,isactive,clientid
9,OPERACIONAL,True,6947
47,CLUSTER 13,True,7348
83,Aero,False,25
```
JSON:
```json
{"clientid": 6947, "id": 9, "isactive": true, "name": "OPERACIONAL"}
{"clientid": 7348, "id": 47, "isactive": true, "name": "CLUSTER 13"}
{"clientid": 25, "id": 83, "isactive": false, "name": "Aero"}
```
Here a copy/paste representation of the records exported to Parquet:
```plain
id name isactive clientid
9 OPERACIONAL true 6947
47 CLUSTER 13 true 7348
83 Aero false 25
```
And this is the schema of the exported parquet file:
```csv
Column name Data type Nullable Metadata
id Int64 true {}
name String true {}
isactive Bool true {}
clientid Int64 true {}
```
## Additional Insights
### Other Operators with BOOL mapping
Looking more in the source code I found a couple of Operators that already have the target mapping defined as `BOOL` like this proposed fix:
#### PostgresToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/postgres_to_gcs.py:112
class PostgresToGCSOperator(BaseSQLToGCSOperator):
type_map = {
1114: "DATETIME",
1184: "TIMESTAMP",
1082: "DATE",
1083: "TIME",
1005: "INTEGER",
1007: "INTEGER",
1016: "INTEGER",
20: "INTEGER",
21: "INTEGER",
23: "INTEGER",
16: "BOOL", # <-------- MAPS boolean/16 to BOOL ---<
700: "FLOAT",
701: "FLOAT",
1700: "FLOAT",
}
```
#### TrinoToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/trino_to_gcs.py:159
class TrinoToGCSOperator(BaseSQLToGCSOperator):
type_map = {
"BOOLEAN": "BOOL",# <-------- MAPS BOOLEAN to BOOL ---<
"TINYINT": "INT64",
"SMALLINT": "INT64",
"INTEGER": "INT64",
"BIGINT": "INT64",
"REAL": "FLOAT64",
"DOUBLE": "FLOAT64",
"DECIMAL": "NUMERIC",
"VARCHAR": "STRING",
"CHAR": "STRING",
"VARBINARY": "BYTES",
"JSON": "STRING",
"DATE": "DATE",
"TIME": "TIME",
# BigQuery don't time with timezone native.
"TIME WITH TIME ZONE": "STRING",
"TIMESTAMP": "TIMESTAMP",
# BigQuery supports a narrow range of time zones during import.
# You should use TIMESTAMP function, if you want have TIMESTAMP type
"TIMESTAMP WITH TIME ZONE": "STRING",
"IPADDRESS": "STRING",
"UUID": "STRING",
}
```
#### CassandraToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/cassandra_to_gcs.py:128
class CassandraToGCSOperator(BaseOperator):
CQL_TYPE_MAP = {
"BytesType": "STRING",
"DecimalType": "FLOAT",
"UUIDType": "STRING",
"BooleanType": "BOOL", # <-------- MAPS BOOLEAN to BOOL ---<
"ByteType": "INTEGER",
"AsciiType": "STRING",
"FloatType": "FLOAT",
"DoubleType": "FLOAT",
"LongType": "INTEGER",
"Int32Type": "INTEGER",
"IntegerType": "INTEGER",
"InetAddressType": "STRING",
"CounterColumnType": "INTEGER",
"DateType": "TIMESTAMP",
"SimpleDateType": "DATE",
"TimestampType": "TIMESTAMP",
"TimeUUIDType": "STRING",
"ShortType": "INTEGER",
"TimeType": "TIME",
"DurationType": "INTEGER",
"UTF8Type": "STRING",
"VarcharType": "STRING",
}
```
#### PrestoToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/presto_to_gcs.py:156
class PrestoToGCSOperator(BaseSQLToGCSOperator):
type_map = {
"BOOLEAN": "BOOL",# <-------- MAPS BOOLEAN to BOOL ---<
"TINYINT": "INT64",
"SMALLINT": "INT64",
"INTEGER": "INT64",
"BIGINT": "INT64",
"REAL": "FLOAT64",
"DOUBLE": "FLOAT64",
"DECIMAL": "NUMERIC",
"VARCHAR": "STRING",
"CHAR": "STRING",
"VARBINARY": "BYTES",
"JSON": "STRING",
"DATE": "DATE",
"TIME": "TIME",
# BigQuery don't time with timezone native.
"TIME WITH TIME ZONE": "STRING",
"TIMESTAMP": "TIMESTAMP",
# BigQuery supports a narrow range of time zones during import.
# You should use TIMESTAMP function, if you want have TIMESTAMP type
"TIMESTAMP WITH TIME ZONE": "STRING",
"IPADDRESS": "STRING",
"UUID": "STRING",
}
```
### Other Operators with BOOLEAN mapping
I've also found a couple Operator with the target mapping defined as `BOOL` unlike this proposed fix.
It is possible that the suffer the same issue as the code before this fix because the type names will mismatch.
#### OracleToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/oracle_to_gcs.py:57
class OracleToGCSOperator(BaseSQLToGCSOperator):
type_map = {
oracledb.DB_TYPE_BINARY_DOUBLE: "DECIMAL",
oracledb.DB_TYPE_BINARY_FLOAT: "DECIMAL",
oracledb.DB_TYPE_BINARY_INTEGER: "INTEGER",
oracledb.DB_TYPE_BOOLEAN: "BOOLEAN", # <-------- MAPS BOOLEAN to BOOLEAN ---<
oracledb.DB_TYPE_DATE: "TIMESTAMP",
oracledb.DB_TYPE_NUMBER: "NUMERIC",
oracledb.DB_TYPE_TIMESTAMP: "TIMESTAMP",
oracledb.DB_TYPE_TIMESTAMP_LTZ: "TIMESTAMP",
oracledb.DB_TYPE_TIMESTAMP_TZ: "TIMESTAMP",
}
```
#### MySQLToGCSOperator
Notice that MySQLToGCSOperator maps BIT to a INTEGER data type intead of BOOLEAN:
```python
# providers/google/src/airflow/providers/google/cloud/transfers/mysql_to_gcs.py:63
class MySQLToGCSOperator(BaseSQLToGCSOperator):
type_map = {
FIELD_TYPE.BIT: "INTEGER", # <-------- MAPS BIT to INTEGER ---<
FIELD_TYPE.DATETIME: "TIMESTAMP",
FIELD_TYPE.DATE: "TIMESTAMP",
FIELD_TYPE.DECIMAL: "FLOAT",
FIELD_TYPE.NEWDECIMAL: "FLOAT",
FIELD_TYPE.DOUBLE: "FLOAT",
FIELD_TYPE.FLOAT: "FLOAT",
FIELD_TYPE.INT24: "INTEGER",
FIELD_TYPE.LONG: "INTEGER",
FIELD_TYPE.LONGLONG: "INTEGER",
FIELD_TYPE.SHORT: "INTEGER",
FIELD_TYPE.TIME: "TIME",
FIELD_TYPE.TIMESTAMP: "TIMESTAMP",
FIELD_TYPE.TINY: "INTEGER",
FIELD_TYPE.YEAR: "INTEGER",
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "MaksYermak (via GitHub)" <gi...@apache.org>.
MaksYermak commented on PR #57514:
URL: https://github.com/apache/airflow/pull/57514#issuecomment-3497824423
> Thanks for the thorough investigation! LGTM, I think that we're good to go and we could handle the mentioned issues later.
>
> @MaksYermak do you have additional comments before merging?
@juarezr thank you for your explanation and deep research!
@shahar1 yes I have one more comment.
I have checked the code and I noticed that [field_to_bigquery](https://github.com/apache/airflow/blob/main/providers/google/src/airflow/providers/google/cloud/transfers/mssql_to_gcs.py#L98) from `MSSQLToGCSOperator` is only one function in the code which uses values from `self.type_map` which is changed by this PR. This function is called in two places [_convert_parquet_schema](https://github.com/apache/airflow/blob/main/providers/google/src/airflow/providers/google/cloud/transfers/sql_to_gcs.py#L387) and [_write_local_schema_file](https://github.com/apache/airflow/blob/main/providers/google/src/airflow/providers/google/cloud/transfers/sql_to_gcs.py#L441). As we know this PR fixes the problem in `_convert_parquet_schema`. But I am not sure that this code does not affect the `_write_local_schema_file` function which the code uses for generate schema in `json` format. I see that `_write_local_schema_file` runs `field_to_bigquery` in case when for the operator `schema_filename` is pr
esent and `schema` is not present, [here](https://github.com/apache/airflow/blob/main/providers/google/src/airflow/providers/google/cloud/transfers/sql_to_gcs.py#L457).
@juarezr could I ask to check the scenario with JSON format for `MSSQLToGCSOperator` when in parameters `schema_filename` is present and `schema` is not present and share with us the results that file with schema is generating successfully for JSON format?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #57514:
URL: https://github.com/apache/airflow/pull/57514
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "MaksYermak (via GitHub)" <gi...@apache.org>.
MaksYermak commented on code in PR #57514:
URL: https://github.com/apache/airflow/pull/57514#discussion_r2480697527
##########
providers/google/src/airflow/providers/google/cloud/transfers/mssql_to_gcs.py:
##########
@@ -67,7 +67,7 @@ class MSSQLToGCSOperator(BaseSQLToGCSOperator):
ui_color = "#e0a98c"
- type_map = {2: "BOOLEAN", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
+ type_map = {2: "BOOL", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
Review Comment:
@juarezr as I understood this `type_map` variable for JSON, CSV and Parquet data types and if you change this `BOOLEAN` to `BOOL` for Parquet format it means for me that it will fail for JSON and CSV formats. Correct me if I am wrong?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #57514:
URL: https://github.com/apache/airflow/pull/57514#issuecomment-3520961427
Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #57514:
URL: https://github.com/apache/airflow/pull/57514#discussion_r2483153081
##########
providers/google/src/airflow/providers/google/cloud/transfers/mssql_to_gcs.py:
##########
@@ -67,7 +67,7 @@ class MSSQLToGCSOperator(BaseSQLToGCSOperator):
ui_color = "#e0a98c"
- type_map = {2: "BOOLEAN", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
+ type_map = {2: "BOOL", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
Review Comment:
Could you please test it with JSON and CSV formats as well?
It won't do much if we replace an existing issue with another :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #57514:
URL: https://github.com/apache/airflow/pull/57514#issuecomment-3463925428
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-prek-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
- Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
Apache Airflow is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "juarezr (via GitHub)" <gi...@apache.org>.
juarezr commented on code in PR #57514:
URL: https://github.com/apache/airflow/pull/57514#discussion_r2484935572
##########
providers/google/src/airflow/providers/google/cloud/transfers/mssql_to_gcs.py:
##########
@@ -67,7 +67,7 @@ class MSSQLToGCSOperator(BaseSQLToGCSOperator):
ui_color = "#e0a98c"
- type_map = {2: "BOOLEAN", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
+ type_map = {2: "BOOL", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
Review Comment:
## Testing results bit_fields
After your advice, I have tested exporting a simple query in the formats PARQUET, CSV, and JSON.
The export process worked fine for all three formats.
I also looked into the source code and found other places that could present the same issue. Please see below for details.
### Results
Query:
```sql
SELECT id, name, isactive, clientid FROM dbo.DriverGroup WHERE id IN (9, 47, 83)
```
This is what was exported to CSV:
```csv
id,name,isactive,clientid
9,OPERACIONAL,True,6947
47,CLUSTER 13,True,7348
83,Aero,False,25
```
JSON:
```json
{"clientid": 6947, "id": 9, "isactive": true, "name": "OPERACIONAL"}
{"clientid": 7348, "id": 47, "isactive": true, "name": "CLUSTER 13"}
{"clientid": 25, "id": 83, "isactive": false, "name": "Aero"}
```
Here a copy/paste representation of the records exported to Parquet:
```plain
id name isactive clientid
9 OPERACIONAL true 6947
47 CLUSTER 13 true 7348
83 Aero false 25
```
And this is the schema of the exported parquet file:
```csv
Column name Data type Nullable Metadata
id Int64 true {}
name String true {}
isactive Bool true {}
clientid Int64 true {}
```
## Additional Insights
### Other Operators with BOOL mapping
Looking more in the source code I found a couple of Operators that already have the target mapping defined as `BOOL` like this proposed fix:
#### PostgresToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/postgres_to_gcs.py:112
class PostgresToGCSOperator(BaseSQLToGCSOperator):
type_map = {
1114: "DATETIME",
1184: "TIMESTAMP",
1082: "DATE",
1083: "TIME",
1005: "INTEGER",
1007: "INTEGER",
1016: "INTEGER",
20: "INTEGER",
21: "INTEGER",
23: "INTEGER",
16: "BOOL", # <-------- MAPS boolean/16 to BOOL ---<
700: "FLOAT",
701: "FLOAT",
1700: "FLOAT",
}
```
#### TrinoToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/trino_to_gcs.py:159
class TrinoToGCSOperator(BaseSQLToGCSOperator):
type_map = {
"BOOLEAN": "BOOL",# <-------- MAPS BOOLEAN to BOOL ---<
"TINYINT": "INT64",
"SMALLINT": "INT64",
"INTEGER": "INT64",
"BIGINT": "INT64",
"REAL": "FLOAT64",
"DOUBLE": "FLOAT64",
"DECIMAL": "NUMERIC",
"VARCHAR": "STRING",
"CHAR": "STRING",
"VARBINARY": "BYTES",
"JSON": "STRING",
"DATE": "DATE",
"TIME": "TIME",
# BigQuery don't time with timezone native.
"TIME WITH TIME ZONE": "STRING",
"TIMESTAMP": "TIMESTAMP",
# BigQuery supports a narrow range of time zones during import.
# You should use TIMESTAMP function, if you want have TIMESTAMP type
"TIMESTAMP WITH TIME ZONE": "STRING",
"IPADDRESS": "STRING",
"UUID": "STRING",
}
```
#### CassandraToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/cassandra_to_gcs.py:128
class CassandraToGCSOperator(BaseOperator):
CQL_TYPE_MAP = {
"BytesType": "STRING",
"DecimalType": "FLOAT",
"UUIDType": "STRING",
"BooleanType": "BOOL", # <-------- MAPS BOOLEAN to BOOL ---<
"ByteType": "INTEGER",
"AsciiType": "STRING",
"FloatType": "FLOAT",
"DoubleType": "FLOAT",
"LongType": "INTEGER",
"Int32Type": "INTEGER",
"IntegerType": "INTEGER",
"InetAddressType": "STRING",
"CounterColumnType": "INTEGER",
"DateType": "TIMESTAMP",
"SimpleDateType": "DATE",
"TimestampType": "TIMESTAMP",
"TimeUUIDType": "STRING",
"ShortType": "INTEGER",
"TimeType": "TIME",
"DurationType": "INTEGER",
"UTF8Type": "STRING",
"VarcharType": "STRING",
}
```
#### PrestoToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/presto_to_gcs.py:156
class PrestoToGCSOperator(BaseSQLToGCSOperator):
type_map = {
"BOOLEAN": "BOOL",# <-------- MAPS BOOLEAN to BOOL ---<
"TINYINT": "INT64",
"SMALLINT": "INT64",
"INTEGER": "INT64",
"BIGINT": "INT64",
"REAL": "FLOAT64",
"DOUBLE": "FLOAT64",
"DECIMAL": "NUMERIC",
"VARCHAR": "STRING",
"CHAR": "STRING",
"VARBINARY": "BYTES",
"JSON": "STRING",
"DATE": "DATE",
"TIME": "TIME",
# BigQuery don't time with timezone native.
"TIME WITH TIME ZONE": "STRING",
"TIMESTAMP": "TIMESTAMP",
# BigQuery supports a narrow range of time zones during import.
# You should use TIMESTAMP function, if you want have TIMESTAMP type
"TIMESTAMP WITH TIME ZONE": "STRING",
"IPADDRESS": "STRING",
"UUID": "STRING",
}
```
### Other Operators with BOOLEAN mapping
I've also found a couple Operator with the target mapping defined as `BOOLEAN`, unlike this proposed fix.
They may have the same issue as the code before this fix because the type names will mismatch.
#### OracleToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/oracle_to_gcs.py:57
class OracleToGCSOperator(BaseSQLToGCSOperator):
type_map = {
oracledb.DB_TYPE_BINARY_DOUBLE: "DECIMAL",
oracledb.DB_TYPE_BINARY_FLOAT: "DECIMAL",
oracledb.DB_TYPE_BINARY_INTEGER: "INTEGER",
oracledb.DB_TYPE_BOOLEAN: "BOOLEAN", # <-------- MAPS BOOLEAN to BOOLEAN ---<
oracledb.DB_TYPE_DATE: "TIMESTAMP",
oracledb.DB_TYPE_NUMBER: "NUMERIC",
oracledb.DB_TYPE_TIMESTAMP: "TIMESTAMP",
oracledb.DB_TYPE_TIMESTAMP_LTZ: "TIMESTAMP",
oracledb.DB_TYPE_TIMESTAMP_TZ: "TIMESTAMP",
}
```
#### MySQLToGCSOperator
Notice that MySQLToGCSOperator maps BIT to a INTEGER data type intead of BOOLEAN:
```python
# providers/google/src/airflow/providers/google/cloud/transfers/mysql_to_gcs.py:63
class MySQLToGCSOperator(BaseSQLToGCSOperator):
type_map = {
FIELD_TYPE.BIT: "INTEGER", # <-------- MAPS BIT to INTEGER ---<
FIELD_TYPE.DATETIME: "TIMESTAMP",
FIELD_TYPE.DATE: "TIMESTAMP",
FIELD_TYPE.DECIMAL: "FLOAT",
FIELD_TYPE.NEWDECIMAL: "FLOAT",
FIELD_TYPE.DOUBLE: "FLOAT",
FIELD_TYPE.FLOAT: "FLOAT",
FIELD_TYPE.INT24: "INTEGER",
FIELD_TYPE.LONG: "INTEGER",
FIELD_TYPE.LONGLONG: "INTEGER",
FIELD_TYPE.SHORT: "INTEGER",
FIELD_TYPE.TIME: "TIME",
FIELD_TYPE.TIMESTAMP: "TIMESTAMP",
FIELD_TYPE.TINY: "INTEGER",
FIELD_TYPE.YEAR: "INTEGER",
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "juarezr (via GitHub)" <gi...@apache.org>.
juarezr commented on PR #57514:
URL: https://github.com/apache/airflow/pull/57514#issuecomment-3507242927
> @MaksYermak
>
> @juarezr could I ask you to check the scenario with JSON format for `MSSQLToGCSOperator` when in parameters `schema_filename` is present and `schema` is not present and share with us the results that file with schema is generating successfully for JSON format?
@MaksYermak,
The dag/task executed successfully. Please check the source code below.
The only unexpected thing that happened is that the schema file was also uploaded to the same path in the bucket as the local filename:
- Local: `/tmp/TEST_QUERY_SCHEMA_JSON_FILE.json`
- Remote: `gs://my-bucket//tmp/TEST_QUERY_SCHEMA_JSON_FILE.json`
I hope that I've interpreted correctly you request.
### Dag Souce Code
```python
TEST_QUERY = """
SELECT TOP 5
TABLE_CATALOG,
TABLE_SCHEMA,
TABLE_NAME,
TABLE_TYPE,
CAST(
CASE WHEN TABLE_TYPE = 'BASE TABLE' THEN 1 ELSE 0 END
AS BIT) AS IS_BASE_TABLE
FROM INFORMATION_SCHEMA.TABLES
ORDER BY 1, 2, 3
"""
TEST_QUERY_SCHEMA_JSON_FILE = "/tmp/TEST_QUERY_SCHEMA_JSON_FILE.json"
TEST_QUERY_SCHEMA_JSON = """
[
{
"name": "TABLE_CATALOG",
"type": "STRING",
"mode": "REQUIRED",
"description": "MSSQL Database Name"
},
{
"name": "TABLE_SCHEMA",
"type": "STRING",
"mode": "REQUIRED",
"description": "MSSQL Schema Name"gs://my-bucket//tmp/TEST_QUERY_SCHEMA_JSON_FILE.json
"type": "STRING",
"mode": "REQUIRED",
"description": "MSSQL Table Name"
},
{
"name": "TABLE_TYPE",
"type": "STRING",
"mode": "REQUIRED",
"description": "MSSQL Table Type"
},
{
"name": "IS_BASE_TABLE",
"type": "BOOL",
"mode": "NULLABLE",
"description": "MSSQL Table Type is Base Table"
}
]
"""
@dag(
schedule=None,
tags=["test", "connectivity", "storage"],
description="""
### MSSQL Data Transfer Test
This is a simple data pipeline testing data transfer from MSSQL to GCS
""",
)
def test_mssql_gcs():
# Write the schema file to the local filesystem
with open(TEST_QUERY_SCHEMA_JSON_FILE, "w") as f:
f.write(TEST_QUERY_SCHEMA_JSON)
test_mssql_gcs_as_json_schema_file = MSSQLToGCSOperator(
task_id="test_mssql_gcs_as_json_schema_file",
mssql_conn_id=MSSQL_CONN_ID,
gcp_conn_id=GCS_CONN_ID,
sql=TEST_QUERY,
bucket=GCS_BUCKET,
export_format="json",
filename="test/test_mssql_gcs/test_mssql_gcs_as_json_schema_file.json",
schema_filename=TEST_QUERY_SCHEMA_JSON_FILE,
)
# ...
```
### Task log
```json
{"timestamp":"2025-11-09T00:02:32.657940Z","level":"info","event":"DAG bundles loaded: dags-folder, example_dags","logger":"airflow.dag_processing.bundles.manager.DagBundlesManager","filename":"manager.py","lineno":179}
{"timestamp":"2025-11-09T00:02:32.658511Z","level":"info","event":"Filling up the DagBag from /opt/airflow/dags/test_mssql_gcs.py","logger":"airflow.models.dagbag.DagBag","filename":"dagbag.py","lineno":593}
{"timestamp":"2025-11-09T00:02:34.191557Z","level":"info","event":"Task instance is in running state","logger":"task.stdout"}
{"timestamp":"2025-11-09T00:02:34.191652Z","level":"info","event":" Previous state of the Task instance: TaskInstanceState.QUEUED","logger":"task.stdout"}
{"timestamp":"2025-11-09T00:02:34.193007Z","level":"info","event":"Current task name:test_mssql_gcs_as_json_schema_file","logger":"task.stdout"}
{"timestamp":"2025-11-09T00:02:34.193061Z","level":"info","event":"Dag name:test_mssql_gcs","logger":"task.stdout"}
{"timestamp":"2025-11-09T00:02:34.193105Z","level":"info","event":"Executing query","logger":"airflow.task.operators.custom.operators.MSSQLToGCSOperator","filename":"sql_to_gcs.py","lineno":166}
{"timestamp":"2025-11-09T00:02:34.207059Z","level":"info","event":"Writing local schema file","logger":"airflow.task.operators.custom.operators.MSSQLToGCSOperator","filename":"sql_to_gcs.py","lineno":171}
{"timestamp":"2025-11-09T00:02:34.207155Z","level":"info","event":"Starts generating schema","logger":"airflow.task.operators.custom.operators.MSSQLToGCSOperator","filename":"sql_to_gcs.py","lineno":455}
{"timestamp":"2025-11-09T00:02:34.207529Z","level":"info","event":"Using schema for /tmp/TEST_QUERY_SCHEMA_JSON_FILE.json","logger":"airflow.task.operators.custom.operators.MSSQLToGCSOperator","filename":"sql_to_gcs.py","lineno":465}
{"timestamp":"2025-11-09T00:02:34.207807Z","level":"info","event":"Uploading schema file to GCS.","logger":"airflow.task.operators.custom.operators.MSSQLToGCSOperator","filename":"sql_to_gcs.py","lineno":177}
{"timestamp":"2025-11-09T00:02:34.212913Z","level":"warning","event":"Connection schemes (type: google_cloud_platform) shall not contain '_' according to RFC3986.","logger":"airflow.sdk.definitions.connection","filename":"connection.py","lineno":130}
{"timestamp":"2025-11-09T00:02:34.215900Z","level":"info","event":"Getting connection using `google.auth.default()` since no explicit credentials are provided.","logger":"airflow.providers.google.cloud.utils.credentials_provider._CredentialProvider","filename":"credentials_provider.py","lineno":410}
{"timestamp":"2025-11-09T00:02:35.944849Z","level":"info","event":"File /tmp/tmp3ke_phhx uploaded to /tmp/TEST_QUERY_SCHEMA_JSON_FILE.json in my-bucket bucket","logger":"airflow.task.hooks.airflow.providers.google.cloud.hooks.gcs.GCSHook","filename":"gcs.py","lineno":579}
{"timestamp":"2025-11-09T00:02:35.944998Z","level":"info","event":"Writing local data files","logger":"airflow.task.operators.custom.operators.MSSQLToGCSOperator","filename":"sql_to_gcs.py","lineno":185}
{"timestamp":"2025-11-09T00:02:35.945422Z","level":"info","event":"Uploading chunk file #0 to GCS.","logger":"airflow.task.operators.custom.operators.MSSQLToGCSOperator","filename":"sql_to_gcs.py","lineno":190}
{"timestamp":"2025-11-09T00:02:35.951310Z","level":"warning","event":"Connection schemes (type: google_cloud_platform) shall not contain '_' according to RFC3986.","logger":"airflow.sdk.definitions.connection","filename":"connection.py","lineno":130}
{"timestamp":"2025-11-09T00:02:35.952119Z","level":"info","event":"Getting connection using `google.auth.default()` since no explicit credentials are provided.","logger":"airflow.providers.google.cloud.utils.credentials_provider._CredentialProvider","filename":"credentials_provider.py","lineno":410}
{"timestamp":"2025-11-09T00:02:37.522008Z","level":"info","event":"File /tmp/tmp7kq_evsy uploaded to test/test_mssql_gcs/test_mssql_gcs_as_json_schema_file.json in my-bucket bucket","logger":"airflow.task.hooks.airflow.providers.google.cloud.hooks.gcs.GCSHook","filename":"gcs.py","lineno":579}
{"timestamp":"2025-11-09T00:02:37.522115Z","level":"info","event":"Removing local file","logger":"airflow.task.operators.custom.operators.MSSQLToGCSOperator","filename":"sql_to_gcs.py","lineno":193}
{"timestamp":"2025-11-09T00:02:37.522820Z","level":"info","event":"Pushing xcom","ti":"RuntimeTaskInstance(id=UUID('019a65eb-98e6-785d-abdd-4948329cba31'), task_id='test_mssql_gcs_as_json_schema_file', dag_id='test_mssql_gcs', run_id='manual__2025-11-09T00:02:09+00:00', try_number=1, dag_version_id=UUID('019a2724-b18d-73ac-822c-4fdb0764d0c4'), map_index=-1, hostname='airflow', context_carrier={}, task=<Task(MSSQLToGCSOperator): test_mssql_gcs_as_json_schema_file>, bundle_instance=LocalDagBundle(name=dags-folder), max_tries=0, start_date=datetime.datetime(2025, 11, 9, 0, 2, 32, 636275, tzinfo=datetime.timezone.utc), end_date=None, state=<TaskInstanceState.RUNNING: 'running'>, is_mapped=False, rendered_map_index=None)","logger":"task","filename":"task_runner.py","lineno":1357}
{"timestamp":"2025-11-09T00:02:37.550763Z","level":"info","event":"Task instance in success state","logger":"task.stdout"}
{"timestamp":"2025-11-09T00:02:37.550911Z","level":"info","event":" Previous state of the Task instance: TaskInstanceState.RUNNING","logger":"task.stdout"}
{"timestamp":"2025-11-09T00:02:37.552842Z","level":"info","event":"Task operator:<Task(MSSQLToGCSOperator): test_mssql_gcs_as_json_schema_file>","logger":"task.stdout"}
```
### gs://my-bucket//tmp/TEST_QUERY_SCHEMA_JSON_FILE.json
```json
[{"mode": "NULLABLE", "name": "TABLE_CATALOG", "type": "STRING"}, {"mode": "NULLABLE", "name": "TABLE_SCHEMA", "type": "STRING"}, {"mode": "NULLABLE", "name": "TABLE_NAME", "type": "STRING"}, {"mode": "NULLABLE", "name": "TABLE_TYPE", "type": "STRING"}, {"mode": "NULLABLE", "name": "IS_BASE_TABLE", "type": "INTEGER"}]
```
### gs://my-bucket/test/test_mssql_gcs/test_mssql_gcs_as_json_schema_file.json
```json
{"IS_BASE_TABLE": true, "TABLE_CATALOG": "fleet", "TABLE_NAME": "__EFMigrationsHistory", "TABLE_SCHEMA": "dbo", "TABLE_TYPE": "BASE TABLE"}
{"IS_BASE_TABLE": true, "TABLE_CATALOG": "fleet", "TABLE_NAME": "Alert", "TABLE_SCHEMA": "dbo", "TABLE_TYPE": "BASE TABLE"}
{"IS_BASE_TABLE": true, "TABLE_CATALOG": "fleet", "TABLE_NAME": "AlertBlackList", "TABLE_SCHEMA": "dbo", "TABLE_TYPE": "BASE TABLE"}
{"IS_BASE_TABLE": true, "TABLE_CATALOG": "fleet", "TABLE_NAME": "AlertRulesGroup", "TABLE_SCHEMA": "dbo", "TABLE_TYPE": "BASE TABLE"}
{"IS_BASE_TABLE": true, "TABLE_CATALOG": "fleet", "TABLE_NAME": "AlertRulesGroupTrackableObject", "TABLE_SCHEMA": "dbo", "TABLE_TYPE": "BASE TABLE"}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "juarezr (via GitHub)" <gi...@apache.org>.
juarezr commented on code in PR #57514:
URL: https://github.com/apache/airflow/pull/57514#discussion_r2483111520
##########
providers/google/src/airflow/providers/google/cloud/transfers/mssql_to_gcs.py:
##########
@@ -67,7 +67,7 @@ class MSSQLToGCSOperator(BaseSQLToGCSOperator):
ui_color = "#e0a98c"
- type_map = {2: "BOOLEAN", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
+ type_map = {2: "BOOL", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
Review Comment:
Hi @MaksYermak ,
- Currently, the only way you can export columns from an MSSQL table with a datatype BIT to a BOOLEAN column in a parquet file is by specifying the column names in the `bit_fields` property. Otherwise, it will be exported with the INT datatype.
- However, if one does this, the data transfer will fail with the exception described in the summary above.
- This change is meant to fix this bug. It is caused by a mismatch that happens between this definition and the place where it is used to determine the column type.
To allow us to see clearly the mismatch, I'm quoting below the text from the issue #57461 that shows both code locations:
----
The issue is in the `MSSQLToGCSOperator` class at line 70:
```python
# Current (incorrect) implementation:
class MSSQLToGCSOperator(BaseSQLToGCSOperator):
type_map = {2: "BOOLEAN", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
# ^^^^^^^^
# This should be "BOOL"
```
The `BaseSQLToGCSOperator._convert_parquet_schema()` method expects `"BOOL"` for boolean types, but `MSSQLToGCSOperator` maps bit fields (type 2) to `"BOOLEAN"`. This mismatch causes PyArrow to fail when converting the schema:
```python
# Type map in base class BaseSQLToGCSOperator:
def _convert_parquet_schema(self, cursor):
type_map = {
"INTEGER": pa.int64(),
"FLOAT": pa.float64(),
"NUMERIC": pa.float64(),
"BIGNUMERIC": pa.float64(),
"BOOL": pa.bool_(), ## This should be the correct key instead of BOOLEAN
"STRING": pa.string(),
"BYTES": pa.binary(),
"DATE": pa.date32(),
"DATETIME": pa.date64(),
"TIMESTAMP": pa.timestamp("s"),
}
```
----
I haven't tried to export to JSON and CSV formats to check if they fail, but:
- Exporting BIT fields to parquet only works with this fix
- I have run the existing test for this operator, and all of them passed.
I hope that I have answered your question properly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "juarezr (via GitHub)" <gi...@apache.org>.
juarezr commented on PR #57514:
URL: https://github.com/apache/airflow/pull/57514#issuecomment-3503006670
> > Thanks for the thorough investigation! LGTM, I think that we're good to go and we could handle the mentioned issues later.
> > @MaksYermak do you have additional comments before merging?
>
> @juarezr thank you for your explanation and deep research!
>
> @shahar1 yes I have one more comment.
>
> @juarezr could I ask you to check the scenario with JSON format for `MSSQLToGCSOperator` when in parameters `schema_filename` is present and `schema` is not present and share with us the results that file with schema is generating successfully for JSON format?
Ok.
I'll try it on the weekend or as soon as I have some spare time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix MSSQLToGCSOperator MSSQL BIT data type conversion to Parquet boolean [airflow]
Posted by "juarezr (via GitHub)" <gi...@apache.org>.
juarezr commented on code in PR #57514:
URL: https://github.com/apache/airflow/pull/57514#discussion_r2484935572
##########
providers/google/src/airflow/providers/google/cloud/transfers/mssql_to_gcs.py:
##########
@@ -67,7 +67,7 @@ class MSSQLToGCSOperator(BaseSQLToGCSOperator):
ui_color = "#e0a98c"
- type_map = {2: "BOOLEAN", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
+ type_map = {2: "BOOL", 3: "INTEGER", 4: "TIMESTAMP", 5: "NUMERIC"}
Review Comment:
## Testing the fix for bit_fields
After your advice, I have tested exporting a simple query to the formats: PARQUET, CSV, and JSON.
I also looked into the source code to understand what the map used in the boolean fields and found that the majority of cases use a map key `BOOL`. However, I also found there are some places that are mapping to `BOOLEAN` and could present the same issue as I've described. Please see for details below.
### Test Results
To test the three formats, I've used a simple DAG with two tasks: One task to export the data from MSSQL to GCS and another task to load the data into BigQuery.
I've run this DAG once for each format. In each run, the data was exported correctly and the schema was generated correctly with the correct data type for the boolean fields in the parquet format.
Here is the diagram of the data pipeline used to export the data from MSSQL to GCS and then to BigQuery:
```plain
┌─────────┐ ┌─────────┐ ┌──────────┐
│ ││ ┌─────────────────────────┐ │ ││ ┌────────────────────────────┐ │ ││
│ MSSQL ││ │ │ │ GCS ││ │ │ │ BigQuery ││
│ ┣──┼─────┼─► MSSQLToGCSOperator ┣─┼──────┼──► ┣─┼─────┼─► GCSToBigQueryOperator ┣─┼───┼──► ││
│ ││ │ │ │ ││ │ │ │ ││
└─────────┘│ └─────────────────────────┘ └─────────┘│ └────────────────────────────┘ └──────────┘│
──────────┘ ──────────┘ ───────────┘
```
### Test Scenario
#### Query
```sql
SELECT id, name, isactive, clientid FROM dbo.DriverGroup WHERE id IN (9, 47, 83)
```
#### CSV
This is what was exported to CSV:
```csv
id,name,isactive,clientid
9,OPERACIONAL,True,6947
47,CLUSTER 13,True,7348
83,Aero,False,25
```
All tasks of this run executed successfully with no need to specify the schema for export/import.
#### JSON
This is what was exported to JSON:
```json
{"clientid": 6947, "id": 9, "isactive": true, "name": "OPERACIONAL"}
{"clientid": 7348, "id": 47, "isactive": true, "name": "CLUSTER 13"}
{"clientid": 25, "id": 83, "isactive": false, "name": "Aero"}
```
This run failed while importing the data in BigQuery due to the export are not preserving the field order as is stated in the SQL query, which is the same field order of the destination table in BigQuery.
But I believe this is unrelated to the issue we've been discussing here. Also, this can be corrected with a schema mapping in the `GCSToBigQueryOperator` operator.
#### Parquet
Here is a copy/paste representation of the records exported to Parquet:
```plain
id name isactive clientid
9 OPERACIONAL true 6947
47 CLUSTER 13 true 7348
83 Aero false 25
```
And this is the schema of the exported parquet file:
```csv
Column name Data type Nullable Metadata
id Int64 true {}
name String true {}
isactive Bool true {}
clientid Int64 true {}
```
## Source Code Investigation
### Operators with BOOL mapping
Looking in the source code, I found a couple of Operators that have the same target mapping defined to `BOOL` as the proposed fix. These Operators are:
- PostgresToGCSOperator
- TrinoToGCSOperator
- CassandraToGCSOperator
- PrestoToGCSOperator
I've concluded that the fix is in the right direction, as these Operators are using the same target mapping defined to `BOOL` as the proposed fix. But I can be wrong in this conclusion.
#### PostgresToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/postgres_to_gcs.py:112
class PostgresToGCSOperator(BaseSQLToGCSOperator):
type_map = {
1114: "DATETIME",
1184: "TIMESTAMP",
1082: "DATE",
1083: "TIME",
1005: "INTEGER",
1007: "INTEGER",
1016: "INTEGER",
20: "INTEGER",
21: "INTEGER",
23: "INTEGER",
16: "BOOL", # <-------- MAPS boolean/16 to BOOL ---<
700: "FLOAT",
701: "FLOAT",
1700: "FLOAT",
}
```
#### TrinoToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/trino_to_gcs.py:159
class TrinoToGCSOperator(BaseSQLToGCSOperator):
type_map = {
"BOOLEAN": "BOOL",# <-------- MAPS BOOLEAN to BOOL ---<
"TINYINT": "INT64",
"SMALLINT": "INT64",
"INTEGER": "INT64",
"BIGINT": "INT64",
"REAL": "FLOAT64",
"DOUBLE": "FLOAT64",
"DECIMAL": "NUMERIC",
"VARCHAR": "STRING",
"CHAR": "STRING",
"VARBINARY": "BYTES",
"JSON": "STRING",
"DATE": "DATE",
"TIME": "TIME",
# BigQuery don't time with timezone native.
"TIME WITH TIME ZONE": "STRING",
"TIMESTAMP": "TIMESTAMP",
# BigQuery supports a narrow range of time zones during import.
# You should use TIMESTAMP function, if you want have TIMESTAMP type
"TIMESTAMP WITH TIME ZONE": "STRING",
"IPADDRESS": "STRING",
"UUID": "STRING",
}
```
#### CassandraToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/cassandra_to_gcs.py:128
class CassandraToGCSOperator(BaseOperator):
CQL_TYPE_MAP = {
"BytesType": "STRING",
"DecimalType": "FLOAT",
"UUIDType": "STRING",
"BooleanType": "BOOL", # <-------- MAPS BOOLEAN to BOOL ---<
"ByteType": "INTEGER",
"AsciiType": "STRING",
"FloatType": "FLOAT",
"DoubleType": "FLOAT",
"LongType": "INTEGER",
"Int32Type": "INTEGER",
"IntegerType": "INTEGER",
"InetAddressType": "STRING",
"CounterColumnType": "INTEGER",
"DateType": "TIMESTAMP",
"SimpleDateType": "DATE",
"TimestampType": "TIMESTAMP",
"TimeUUIDType": "STRING",
"ShortType": "INTEGER",
"TimeType": "TIME",
"DurationType": "INTEGER",
"UTF8Type": "STRING",
"VarcharType": "STRING",
}
```
#### PrestoToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/presto_to_gcs.py:156
class PrestoToGCSOperator(BaseSQLToGCSOperator):
type_map = {
"BOOLEAN": "BOOL",# <-------- MAPS BOOLEAN to BOOL ---<
"TINYINT": "INT64",
"SMALLINT": "INT64",
"INTEGER": "INT64",
"BIGINT": "INT64",
"REAL": "FLOAT64",
"DOUBLE": "FLOAT64",
"DECIMAL": "NUMERIC",
"VARCHAR": "STRING",
"CHAR": "STRING",
"VARBINARY": "BYTES",
"JSON": "STRING",
"DATE": "DATE",
"TIME": "TIME",
# BigQuery don't time with timezone native.
"TIME WITH TIME ZONE": "STRING",
"TIMESTAMP": "TIMESTAMP",
# BigQuery supports a narrow range of time zones during import.
# You should use TIMESTAMP function, if you want have TIMESTAMP type
"TIMESTAMP WITH TIME ZONE": "STRING",
"IPADDRESS": "STRING",
"UUID": "STRING",
}
```
### Operators with BOOLEAN mapping
I've also found a couple of operators with the target mapping defined as `BOOLEAN`, unlike this proposed fix.
I believe that there is a potential issue with these Operators. Its possible that they may have the same issue as the code before this fix because the type names will mismatch.
However, I'm not sure if this is a real issue or not. Also, I don't have a readily available environment to test this hypothesis.
#### OracleToGCSOperator
```python
# providers/google/src/airflow/providers/google/cloud/transfers/oracle_to_gcs.py:57
class OracleToGCSOperator(BaseSQLToGCSOperator):
type_map = {
oracledb.DB_TYPE_BINARY_DOUBLE: "DECIMAL",
oracledb.DB_TYPE_BINARY_FLOAT: "DECIMAL",
oracledb.DB_TYPE_BINARY_INTEGER: "INTEGER",
oracledb.DB_TYPE_BOOLEAN: "BOOLEAN", # <-------- MAPS BOOLEAN to BOOLEAN ---<
oracledb.DB_TYPE_DATE: "TIMESTAMP",
oracledb.DB_TYPE_NUMBER: "NUMERIC",
oracledb.DB_TYPE_TIMESTAMP: "TIMESTAMP",
oracledb.DB_TYPE_TIMESTAMP_LTZ: "TIMESTAMP",
oracledb.DB_TYPE_TIMESTAMP_TZ: "TIMESTAMP",
}
```
#### MySQLToGCSOperator
Notice that MySQLToGCSOperator maps BIT to an INTEGER data type instead of BOOLEAN:
```python
# providers/google/src/airflow/providers/google/cloud/transfers/mysql_to_gcs.py:63
class MySQLToGCSOperator(BaseSQLToGCSOperator):
type_map = {
FIELD_TYPE.BIT: "INTEGER", # <-------- MAPS BIT to INTEGER ---<
FIELD_TYPE.DATETIME: "TIMESTAMP",
FIELD_TYPE.DATE: "TIMESTAMP",
FIELD_TYPE.DECIMAL: "FLOAT",
FIELD_TYPE.NEWDECIMAL: "FLOAT",
FIELD_TYPE.DOUBLE: "FLOAT",
FIELD_TYPE.FLOAT: "FLOAT",
FIELD_TYPE.INT24: "INTEGER",
FIELD_TYPE.LONG: "INTEGER",
FIELD_TYPE.LONGLONG: "INTEGER",
FIELD_TYPE.SHORT: "INTEGER",
FIELD_TYPE.TIME: "TIME",
FIELD_TYPE.TIMESTAMP: "TIMESTAMP",
FIELD_TYPE.TINY: "INTEGER",
FIELD_TYPE.YEAR: "INTEGER",
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org