Python MySQLdb.constants.FIELD_TYPE.DATE Examples

The following are 5 code examples of MySQLdb.constants.FIELD_TYPE.DATE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module MySQLdb.constants.FIELD_TYPE , or try the search function .
Example #1
Source File: mysql_to_gcs.py    From airflow with Apache License 2.0 5 votes vote down vote up
def convert_type(self, value, schema_type):
        """
        Takes a value from MySQLdb, and converts it to a value that's safe for
        JSON/Google Cloud Storage/BigQuery.

        * Datetimes are converted to UTC seconds.
        * Decimals are converted to floats.
        * Dates are converted to ISO formatted string if given schema_type is
          DATE, or UTC seconds otherwise.
        * Binary type fields are converted to integer if given schema_type is
          INTEGER, or encoded with base64 otherwise. Imported BYTES data must
          be base64-encoded according to BigQuery documentation:
          https://cloud.google.com/bigquery/data-types

        :param value: MySQLdb column value
        :type value: Any
        :param schema_type: BigQuery data type
        :type schema_type: str
        """
        if value is None:
            return value
        if isinstance(value, datetime):
            value = calendar.timegm(value.timetuple())
        elif isinstance(value, timedelta):
            value = value.total_seconds()
        elif isinstance(value, Decimal):
            value = float(value)
        elif isinstance(value, date):
            if schema_type == "DATE":
                value = value.isoformat()
            else:
                value = calendar.timegm(value.timetuple())
        elif isinstance(value, bytes):
            if schema_type == "INTEGER":
                value = int.from_bytes(value, "big")
            else:
                value = base64.standard_b64encode(value).decode('ascii')
        return value 
Example #2
Source File: test_MySQLdb_nonstandard.py    From mysqlclient-python with GNU General Public License v2.0 5 votes vote down vote up
def test_set_inequality_membership(self):
        self.assertTrue(FIELD_TYPE.DATE != MySQLdb.STRING) 
Example #3
Source File: __init__.py    From mysqlclient-python with GNU General Public License v2.0 5 votes vote down vote up
def test_DBAPISet_set_inequality_membership():
    assert FIELD_TYPE.DATE != STRING 
Example #4
Source File: __init__.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_DBAPISet_set_inequality_membership():
    assert FIELD_TYPE.DATE != STRING 
Example #5
Source File: __init__.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_DBAPISet_set_inequality_membership():
    assert FIELD_TYPE.DATE != STRING