6378d4bc06
### What changes were proposed in this pull request? - Remove SQLContext.createExternalTable and Catalog.createExternalTable, deprecated in favor of createTable since 2.2.0, plus tests of deprecated methods - Remove HiveContext, deprecated in 2.0.0, in favor of `SparkSession.builder.enableHiveSupport` - Remove deprecated KinesisUtils.createStream methods, plus tests of deprecated methods, deprecate in 2.2.0 - Remove deprecated MLlib (not Spark ML) linear method support, mostly utility constructors and 'train' methods, and associated docs. This includes methods in LinearRegression, LogisticRegression, Lasso, RidgeRegression. These have been deprecated since 2.0.0 - Remove deprecated Pyspark MLlib linear method support, including LogisticRegressionWithSGD, LinearRegressionWithSGD, LassoWithSGD - Remove 'runs' argument in KMeans.train() method, which has been a no-op since 2.0.0 - Remove deprecated ChiSqSelector isSorted protected method - Remove deprecated 'yarn-cluster' and 'yarn-client' master argument in favor of 'yarn' and deploy mode 'cluster', etc Notes: - I was not able to remove deprecated DataFrameReader.json(RDD) in favor of DataFrameReader.json(Dataset); the former was deprecated in 2.2.0, but, it is still needed to support Pyspark's .json() method, which can't use a Dataset. - Looks like SQLContext.createExternalTable was not actually deprecated in Pyspark, but, almost certainly was meant to be? Catalog.createExternalTable was. - I afterwards noted that the toDegrees, toRadians functions were almost removed fully in SPARK-25908, but Felix suggested keeping just the R version as they hadn't been technically deprecated. I'd like to revisit that. Do we really want the inconsistency? I'm not against reverting it again, but then that implies leaving SQLContext.createExternalTable just in Pyspark too, which seems weird. - I *kept* LogisticRegressionWithSGD, LinearRegressionWithSGD, LassoWithSGD, RidgeRegressionWithSGD in Pyspark, though deprecated, as it is hard to remove them (still used by StreamingLogisticRegressionWithSGD?) and they are not fully removed in Scala. Maybe should not have been deprecated. ### Why are the changes needed? Deprecated items are easiest to remove in a major release, so we should do so as much as possible for Spark 3. This does not target items deprecated 'recently' as of Spark 2.3, which is still 18 months old. ### Does this PR introduce any user-facing change? Yes, in that deprecated items are removed from some public APIs. ### How was this patch tested? Existing tests. Closes #25684 from srowen/SPARK-28980. Lead-authored-by: Sean Owen <sean.owen@databricks.com> Co-authored-by: HyukjinKwon <gurwls223@apache.org> Signed-off-by: Sean Owen <sean.owen@databricks.com>
102 lines
5.3 KiB
Python
102 lines
5.3 KiB
Python
#
|
|
# 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.
|
|
#
|
|
|
|
from pyspark.serializers import NoOpSerializer
|
|
from pyspark.storagelevel import StorageLevel
|
|
from pyspark.streaming import DStream
|
|
from pyspark.util import _print_missing_jar
|
|
|
|
|
|
__all__ = ['KinesisUtils', 'InitialPositionInStream', 'utf8_decoder']
|
|
|
|
|
|
def utf8_decoder(s):
|
|
""" Decode the unicode as UTF-8 """
|
|
if s is None:
|
|
return None
|
|
return s.decode('utf-8')
|
|
|
|
|
|
class KinesisUtils(object):
|
|
|
|
@staticmethod
|
|
def createStream(ssc, kinesisAppName, streamName, endpointUrl, regionName,
|
|
initialPositionInStream, checkpointInterval,
|
|
storageLevel=StorageLevel.MEMORY_AND_DISK_2,
|
|
awsAccessKeyId=None, awsSecretKey=None, decoder=utf8_decoder,
|
|
stsAssumeRoleArn=None, stsSessionName=None, stsExternalId=None):
|
|
"""
|
|
Create an input stream that pulls messages from a Kinesis stream. This uses the
|
|
Kinesis Client Library (KCL) to pull messages from Kinesis.
|
|
|
|
.. note:: The given AWS credentials will get saved in DStream checkpoints if checkpointing
|
|
is enabled. Make sure that your checkpoint directory is secure.
|
|
|
|
:param ssc: StreamingContext object
|
|
:param kinesisAppName: Kinesis application name used by the Kinesis Client Library (KCL) to
|
|
update DynamoDB
|
|
:param streamName: Kinesis stream name
|
|
:param endpointUrl: Url of Kinesis service (e.g., https://kinesis.us-east-1.amazonaws.com)
|
|
:param regionName: Name of region used by the Kinesis Client Library (KCL) to update
|
|
DynamoDB (lease coordination and checkpointing) and CloudWatch (metrics)
|
|
:param initialPositionInStream: In the absence of Kinesis checkpoint info, this is the
|
|
worker's initial starting position in the stream. The
|
|
values are either the beginning of the stream per Kinesis'
|
|
limit of 24 hours (InitialPositionInStream.TRIM_HORIZON) or
|
|
the tip of the stream (InitialPositionInStream.LATEST).
|
|
:param checkpointInterval: Checkpoint interval for Kinesis checkpointing. See the Kinesis
|
|
Spark Streaming documentation for more details on the different
|
|
types of checkpoints.
|
|
:param storageLevel: Storage level to use for storing the received objects (default is
|
|
StorageLevel.MEMORY_AND_DISK_2)
|
|
:param awsAccessKeyId: AWS AccessKeyId (default is None. If None, will use
|
|
DefaultAWSCredentialsProviderChain)
|
|
:param awsSecretKey: AWS SecretKey (default is None. If None, will use
|
|
DefaultAWSCredentialsProviderChain)
|
|
:param decoder: A function used to decode value (default is utf8_decoder)
|
|
:param stsAssumeRoleArn: ARN of IAM role to assume when using STS sessions to read from
|
|
the Kinesis stream (default is None).
|
|
:param stsSessionName: Name to uniquely identify STS sessions used to read from Kinesis
|
|
stream, if STS is being used (default is None).
|
|
:param stsExternalId: External ID that can be used to validate against the assumed IAM
|
|
role's trust policy, if STS is being used (default is None).
|
|
:return: A DStream object
|
|
"""
|
|
jlevel = ssc._sc._getJavaStorageLevel(storageLevel)
|
|
jduration = ssc._jduration(checkpointInterval)
|
|
|
|
try:
|
|
helper = ssc._jvm.org.apache.spark.streaming.kinesis.KinesisUtilsPythonHelper()
|
|
except TypeError as e:
|
|
if str(e) == "'JavaPackage' object is not callable":
|
|
_print_missing_jar(
|
|
"Streaming's Kinesis",
|
|
"streaming-kinesis-asl",
|
|
"streaming-kinesis-asl-assembly",
|
|
ssc.sparkContext.version)
|
|
raise
|
|
jstream = helper.createStream(ssc._jssc, kinesisAppName, streamName, endpointUrl,
|
|
regionName, initialPositionInStream, jduration, jlevel,
|
|
awsAccessKeyId, awsSecretKey, stsAssumeRoleArn,
|
|
stsSessionName, stsExternalId)
|
|
stream = DStream(jstream, ssc, NoOpSerializer())
|
|
return stream.map(lambda v: decoder(v))
|
|
|
|
|
|
class InitialPositionInStream(object):
|
|
LATEST, TRIM_HORIZON = (0, 1)
|