From 6a3257eb703bf6d52988bce2a7d0d9cb6d1a738e Mon Sep 17 00:00:00 2001 From: Mingmin Chen Date: Wed, 10 Aug 2016 22:37:10 -0700 Subject: [PATCH 1/2] Make lz4 compression working --- python-hadoop/__init__.py | 0 python-hadoop/hadoop/io/__init__.py | 1 + python-hadoop/hadoop/io/{ => compress}/Lz4Codec.py | 0 python-hadoop/hadoop/io/compress/__init__.py | 1 + 4 files changed, 2 insertions(+) create mode 100644 python-hadoop/__init__.py rename python-hadoop/hadoop/io/{ => compress}/Lz4Codec.py (100%) diff --git a/python-hadoop/__init__.py b/python-hadoop/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python-hadoop/hadoop/io/__init__.py b/python-hadoop/hadoop/io/__init__.py index 873305c..fff1ee3 100644 --- a/python-hadoop/hadoop/io/__init__.py +++ b/python-hadoop/hadoop/io/__init__.py @@ -24,6 +24,7 @@ import MapFile import SetFile +from BytesWritable import * from Writable import * from IntWritable import * from Text import * diff --git a/python-hadoop/hadoop/io/Lz4Codec.py b/python-hadoop/hadoop/io/compress/Lz4Codec.py similarity index 100% rename from python-hadoop/hadoop/io/Lz4Codec.py rename to python-hadoop/hadoop/io/compress/Lz4Codec.py diff --git a/python-hadoop/hadoop/io/compress/__init__.py b/python-hadoop/hadoop/io/compress/__init__.py index 1d0f940..2235785 100644 --- a/python-hadoop/hadoop/io/compress/__init__.py +++ b/python-hadoop/hadoop/io/compress/__init__.py @@ -17,4 +17,5 @@ # limitations under the License. from CodecPool import * +from Lz4Codec import * From c51463b688e0515d0a7903782df5cc6872ff5749 Mon Sep 17 00:00:00 2001 From: Mingmin Chen Date: Wed, 10 Aug 2016 22:42:08 -0700 Subject: [PATCH 2/2] Add BytesWritable.py --- python-hadoop/hadoop/io/BytesWritable.py | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 python-hadoop/hadoop/io/BytesWritable.py diff --git a/python-hadoop/hadoop/io/BytesWritable.py b/python-hadoop/hadoop/io/BytesWritable.py new file mode 100644 index 0000000..ecac561 --- /dev/null +++ b/python-hadoop/hadoop/io/BytesWritable.py @@ -0,0 +1,60 @@ +#!/usr/bin/env 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 Writable import WritableComparable +from WritableUtils import readVInt, writeVInt + +class BytesWritable(WritableComparable): + def __init__(self): + self._bytes = '' + self._length = 0 + + def getBytes(self): + return self._bytes + + def getLength(self): + return self._length + + def set(self, value): + self._bytes = value + self._length = len(self._bytes) + + def append(self, value): + new_bytes = value + self._bytes += new_bytes + self._length += len(new_bytes) + + def clear(self): + self._length = 0 + self._bytes = '' + + def write(self, data_output): + data_output.writeInt(self._length) + data_output.write(self._bytes) + + def readFields(self, data_input): + self._length = data_input.readInt() + self._bytes = data_input.read(self._length) + + def equal(self, other): + if not isinstance(other, BytesWritable): + return False + return self._bytes == other._bytes and self._length and other._length + + def toString(self): + return self._bytes