spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zasdfgbnm <...@git.apache.org>
Subject [GitHub] spark pull request #18444: [SPARK-16542][SQL][PYSPARK] Fix bugs about types ...
Date Wed, 19 Jul 2017 01:00:23 GMT
Github user zasdfgbnm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18444#discussion_r128131993
  
    --- Diff: python/pyspark/sql/types.py ---
    @@ -938,12 +1016,17 @@ def _infer_type(obj):
                     return MapType(_infer_type(key), _infer_type(value), True)
             else:
                 return MapType(NullType(), NullType(), True)
    -    elif isinstance(obj, (list, array)):
    +    elif isinstance(obj, list):
             for v in obj:
                 if v is not None:
                     return ArrayType(_infer_type(obj[0]), True)
             else:
                 return ArrayType(NullType(), True)
    +    elif isinstance(obj, array):
    +        if obj.typecode in _array_type_mappings:
    +            return ArrayType(_array_type_mappings[obj.typecode](), False)
    +        else:
    +            raise TypeError("not supported type: array(%s)" % obj.typecode)
    --- End diff --
    
    Test result for python 2 is here:
    ```python
    Python 2.7.13 (default, Jul  2 2017, 22:24:59) 
    [GCC 7.1.1 20170621] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
    Setting default log level to "WARN".
    To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
    17/07/18 20:59:26 WARN NativeCodeLoader: Unable to load native-hadoop library for your
platform... using builtin-java classes where applicable
    17/07/18 20:59:26 WARN Utils: Your hostname, archlinux resolves to a loopback address:
127.0.0.1; using 192.168.88.2 instead (on interface eno1)
    17/07/18 20:59:26 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
    17/07/18 20:59:29 WARN ObjectStore: Failed to get database global_temp, returning NoSuchObjectException
    Welcome to
          ____              __
         / __/__  ___ _____/ /__
        _\ \/ _ \/ _ `/ __/  '_/
       /__ / .__/\_,_/_/ /_/\_\   version 2.2.0
          /_/
    
    Using Python version 2.7.13 (default, Jul  2 2017 22:24:59)
    SparkSession available as 'spark'.
    >>> import array,sys
    >>> from pyspark import *
    >>> from pyspark.sql import *
    >>> 
    >>> def assertCollectSuccess(typecode, value):
    ...      row = Row(myarray=array.array(typecode, [value]))
    ...      df = spark.createDataFrame([row])
    ...      print(typecode)
    ...      df.show()
    ... 
    >>> assertCollectSuccess('u',u'a')
    u
    +-------+
    |myarray|
    +-------+
    |    [a]|
    +-------+
    
    >>> assertCollectSuccess('f',1.2)
    f
    +-------+
    |myarray|
    +-------+
    | [null]|
    +-------+
    
    >>> assertCollectSuccess('d',1.2)
    d
    +-------+
    |myarray|
    +-------+
    |  [1.2]|
    +-------+
    
    >>> assertCollectSuccess('b',1)
    b
    +-------+
    |myarray|
    +-------+
    | [null]|
    +-------+
    
    >>> assertCollectSuccess('B',1)
    B
    +-------+
    |myarray|
    +-------+
    | [null]|
    +-------+
    
    >>> assertCollectSuccess('h',1)
    h
    +-------+
    |myarray|
    +-------+
    | [null]|
    +-------+
    
    >>> assertCollectSuccess('H',1)
    H
    +-------+
    |myarray|
    +-------+
    |    [1]|
    +-------+
    
    >>> assertCollectSuccess('i',1)
    i
    +-------+
    |myarray|
    +-------+
    |    [1]|
    +-------+
    
    >>> assertCollectSuccess('I',1)
    I
    +-------+
    |myarray|
    +-------+
    |    [1]|
    +-------+
    
    >>> assertCollectSuccess('l',1)
    l
    +-------+
    |myarray|
    +-------+
    |    [1]|
    +-------+
    
    >>> assertCollectSuccess('L',1)
    L
    +-------+
    |myarray|
    +-------+
    |    [1]|
    +-------+
    
    >>> 
    >>> 
    >>> if sys.version_info[0] > 2:
    ...     assertCollectSuccess('q',1)
    ...     assertCollectSuccess('Q',1)
    ... 
    >>> 
    >>> if sys.version_info[0] < 3:
    ...     assertCollectSuccess('c','a')
    ... 
    c
    +-------+
    |myarray|
    +-------+
    |    [a]|
    +-------+
    
    >>>
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message