Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/1346#discussion_r15551776
--- Diff: python/pyspark/sql.py ---
@@ -20,8 +20,457 @@
from py4j.protocol import Py4JError
-__all__ = ["SQLContext", "HiveContext", "LocalHiveContext",
"TestHiveContext", "SchemaRDD", "Row"]
+__all__ = [
+ "StringType", "BinaryType", "BooleanType", "TimestampType",
"DecimalType",
+ "DoubleType", "FloatType", "ByteType", "IntegerType", "LongType",
+ "ShortType", "ArrayType", "MapType", "StructField", "StructType",
+ "SQLContext", "HiveContext", "LocalHiveContext", "TestHiveContext",
"SchemaRDD", "Row"]
+class PrimitiveTypeSingleton(type):
+ _instances = {}
+ def __call__(cls):
+ if cls not in cls._instances:
+ cls._instances[cls] = super(PrimitiveTypeSingleton,
cls).__call__()
+ return cls._instances[cls]
+
+class StringType(object):
+ """Spark SQL StringType
+
+ The data type representing string values.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "StringType"
+
+class BinaryType(object):
+ """Spark SQL BinaryType
+
+ The data type representing bytearray values.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "BinaryType"
+
+class BooleanType(object):
+ """Spark SQL BooleanType
+
+ The data type representing bool values.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "BooleanType"
+
+class TimestampType(object):
+ """Spark SQL TimestampType
+
+ The data type representing datetime.datetime values.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "TimestampType"
+
+class DecimalType(object):
+ """Spark SQL DecimalType
+
+ The data type representing decimal.Decimal values.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "DecimalType"
+
+class DoubleType(object):
+ """Spark SQL DoubleType
+
+ The data type representing float values.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "DoubleType"
+
+class FloatType(object):
+ """Spark SQL FloatType
+
+ For now, please use L{DoubleType} instead of using L{FloatType}.
+ Because query evaluation is done in Scala, java.lang.Double will be be
used
+ for Python float numbers. Because the underlying JVM type of FloatType
is
+ java.lang.Float (in Java) and Float (in scala), there will be a
java.lang.ClassCastException
+ if FloatType (Python) is used.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "FloatType"
+
+class ByteType(object):
+ """Spark SQL ByteType
+
+ For now, please use L{IntegerType} instead of using L{ByteType}.
+ Because query evaluation is done in Scala, java.lang.Integer will be
be used
+ for Python int numbers. Because the underlying JVM type of ByteType is
+ java.lang.Byte (in Java) and Byte (in scala), there will be a
java.lang.ClassCastException
+ if ByteType (Python) is used.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "ByteType"
+
+class IntegerType(object):
+ """Spark SQL IntegerType
+
+ The data type representing int values.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "IntegerType"
+
+class LongType(object):
+ """Spark SQL LongType
+
+ The data type representing long values. If the any value is beyond the
range of
+ [-9223372036854775808, 9223372036854775807], please use DecimalType.
+
+ """
+ __metaclass__ = PrimitiveTypeSingleton
+
+ def __repr__(self):
+ return "LongType"
+
+class ShortType(object):
+ """Spark SQL ShortType
+
+ For now, please use L{IntegerType} instead of using L{ShortType}.
--- End diff --
In Java/Scala, when user loads data from csv file, they need to do this
kind of type conversion, it will be better if we could do this for them
automatically.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---