Github user yhuai commented on a diff in the pull request:
https://github.com/apache/spark/pull/11444#discussion_r54822526
--- Diff: python/pyspark/sql/context.py ---
@@ -63,7 +63,42 @@ def toDF(self, schema=None, sampleRatio=None):
"""
return sqlContext.createDataFrame(self, schema, sampleRatio)
+ def schema(self, datatype):
+ """
+ Converts current :class:`RDD` into a :class:`DataFrame` according
to the given data type.
+ Note that, the given datatype must match the real data, or
exception will be thrown at
+ runtime. If the given datatype is not StructType, it will be
wrapped into a StructType as
+ its only field, and the field name will be "value", each record
will also be wrapped into a
+ list, which can be converted to row later.
+
+ :param datatype:
+ a :class:`DataType` or a data type string. The data type
string format equals to
+ `DataType.simpleString`, except that top level struct type can
omit the `struct<>` and
+ numeric types use `typeName()` as their format, e.g. use
`byte` instead of `tinyint` for
+ ByteType. We can also use `int` as a short name for
IntegerType.
+
+ """
+ if isinstance(datatype, basestring):
+ datatype = _parse_datatype_string(datatype)
+
+ if not isinstance(datatype, DataType):
+ raise TypeError("datatype should be DataType or string, but
got: %s" % datatype)
+ else:
+ def verify(obj):
+ _verify_type(obj, datatype)
--- End diff --
Since Python and Scala/Java have different range of int/long numbers, does
_verify_type check if the actual value is within the allowed range?
---
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.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]