Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions python/pyspark/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# limitations under the License.
#

import re
import sys
import inspect
from py4j.protocol import Py4JJavaError
Expand Down Expand Up @@ -61,6 +62,26 @@ def _get_argspec(f):
return argspec


def majorMinorVersion(version):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think he asked to add VersionUtils class.

"""
Get major and minor version numbers for given Spark version string.

>>> version = "2.4.0"
>>> majorMinorVersion(version)
(2, 4)

>>> version = "abc"
>>> majorMinorVersion(version) is None
True

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. Could you remove redundant empty line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yap, thanks.

"""
m = re.search('^(\d+)\.(\d+)(\..*)?$', version)
if m is None:
return None
else:
return (int(m.group(1)), int(m.group(2)))


if __name__ == "__main__":
import doctest
(failure_count, test_count) = doctest.testmod()
Expand Down