Skip to content

Commit 0625257

Browse files
harshavardhananitisht
authored andcommitted
Re-implement select_object_content implementation (#793)
This change fixes multiple issues - handles unicode boundaries properly for special delimiters - handle zero payload 'Cont' event messages - handle error messages properly
1 parent 84e57b6 commit 0625257

File tree

15 files changed

+400
-349
lines changed

15 files changed

+400
-349
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ var/
2222
*.egg-info/
2323
.installed.cfg
2424
*.egg
25+
*~
26+
.#*
27+
#*

docs/API.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ __Return Value__
690690
|``obj``| _SelectObjectReader_ |Select_object_reader object. |
691691

692692

693-
694693
__Example__
695694

696695

@@ -736,7 +735,7 @@ try:
736735
# Get the stats
737736
print(data.stats())
738737

739-
except CRCValidationError as err:
738+
except SelectCRCValidationError as err:
740739
print(err)
741740
except ResponseError as err:
742741
print(err)

examples/select_object_content.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
from minio import Minio
1919
from minio.error import ResponseError
20-
from minio.select_object_reader import CRCValidationError
21-
from minio.select_object_options import (SelectObjectOptions, CSVInput,
22-
JSONInput, RequestProgress,
23-
ParquetInput, InputSerialization,
24-
OutputSerialization, CSVOutput,
25-
JsonOutput)
20+
from minio.select.errors import SelectCRCValidationError, SelectMessageError
21+
from minio.select.options import (SelectObjectOptions, CSVInput,
22+
JSONInput, RequestProgress,
23+
ParquetInput, InputSerialization,
24+
OutputSerialization, CSVOutput,
25+
JsonOutput)
2626

2727
client = Minio('s3.amazonaws.com',
2828
access_key='YOUR-ACCESSKEY',
@@ -71,7 +71,11 @@
7171
# Get the stats
7272
print(data.stats())
7373

74-
except CRCValidationError as err:
74+
except SelectMessageError as err:
7575
print(err)
76+
77+
except SelectCRCValidationError as err:
78+
print(err)
79+
7680
except ResponseError as err:
7781
print(err)

minio/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
__title__ = 'minio-py'
3131
__author__ = 'MinIO, Inc.'
32-
__version__ = '4.0.22'
32+
__version__ = '5.0.0'
3333
__license__ = 'Apache 2.0'
3434
__copyright__ = 'Copyright 2015, 2016, 2017, 2018, 2019 MinIO, Inc.'
3535

@@ -38,6 +38,3 @@
3838
from .post_policy import PostPolicy
3939
from .copy_conditions import CopyConditions
4040
from .definitions import Bucket, Object
41-
from .select_object_reader import SelectObjectReader
42-
43-

minio/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@
7777
is_valid_bucket_notification_config, is_valid_policy_type,
7878
mkdir_p, dump_http, amzprefix_user_metadata,
7979
is_supported_header,is_amz_header)
80-
from .helpers import (MAX_MULTIPART_OBJECT_SIZE,
81-
MAX_PART_SIZE,
80+
from .helpers import (MAX_PART_SIZE,
8281
MAX_POOL_SIZE,
8382
MIN_PART_SIZE,
8483
DEFAULT_PART_SIZE,
@@ -94,7 +93,7 @@
9493
xml_marshal_select)
9594
from .fold_case_dict import FoldCaseDict
9695
from .thread_pool import ThreadPool
97-
from .select_object_reader import SelectObjectReader
96+
from .select import SelectObjectReader
9897

9998
# Comment format.
10099
_COMMENTS = '({0}; {1})'

minio/helpers.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@
5555
MIN_PART_SIZE = 5 * 1024 * 1024 # 5MiB
5656
DEFAULT_PART_SIZE = MIN_PART_SIZE # Currently its 5MiB
5757

58-
59-
# Select Object Content
60-
READ_SIZE_SELECT = 32 * 1024 # Buffer size
61-
SQL = 'SQL' # Value for ExpressionType
62-
EVENT_RECORDS = 'Records' # Event Type is Records
63-
EVENT_PROGRESS = 'Progress' # Event Type Progress
64-
EVENT_STATS = 'Stats' # Event Type Stats
65-
EVENT = 'event' # Message Type is event
66-
EVENT_END = 'End' # Event Type is End
67-
ERROR = 'error' # Message Type is error
68-
6958
_VALID_BUCKETNAME_REGEX = re.compile('^[a-z0-9][a-z0-9\\.\\-]+[a-z0-9]$')
7059
_ALLOWED_HOSTNAME_REGEX = re.compile(
7160
'^((?!-)(?!_)[A-Z_\\d-]{1,63}(?<!-)(?<!_)\\.)*((?!_)(?!-)[A-Z_\\d-]{1,63}(?<!-)(?<!_))$',

minio/select/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
# MinIO Python Library for Amazon S3 Compatible Cloud Storage,
3+
# (C) 2019 MinIO, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""
18+
:copyright: (c) 2019 by MinIO, Inc.
19+
:license: Apache 2.0, see LICENSE for more details.
20+
"""
21+
22+
__title__ = 'minio-py'
23+
__author__ = 'MinIO, Inc.'
24+
__version__ = '0.0.1'
25+
__license__ = 'Apache 2.0'
26+
__copyright__ = 'Copyright 2019 MinIO, Inc.'
27+
28+
from .reader import *
29+
from .helpers import *
30+
from .errors import *
31+
from .options import *

minio/select/errors.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C)
3+
# 2019 MinIO, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""
18+
minio.select.errors
19+
~~~~~~~~~~~~~~~
20+
21+
This module implements the error classes for SelectObject responses.
22+
23+
:copyright: (c) 2019 by MinIO, Inc.
24+
:license: Apache 2.0, see LICENSE for more details.
25+
26+
"""
27+
28+
class SelectMessageError(Exception):
29+
'''
30+
Raised in case of message type 'error'
31+
'''
32+
33+
class SelectCRCValidationError(Exception):
34+
'''
35+
Raised in case of CRC mismatch
36+
'''

minio/select/helpers.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C)
3+
# 2019 MinIO, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""
18+
minio.select.helpers
19+
~~~~~~~~~~~~~~~
20+
21+
This module implements the helper functions for SelectObject responses.
22+
23+
:copyright: (c) 2019 by MinIO, Inc.
24+
:license: Apache 2.0, see LICENSE for more details.
25+
26+
"""
27+
28+
import codecs
29+
from binascii import crc32
30+
31+
SQL = 'SQL' # Value for ExpressionType
32+
EVENT_RECORDS = 'Records' # Event Type is Records
33+
EVENT_PROGRESS = 'Progress' # Event Type Progress
34+
EVENT_STATS = 'Stats' # Event Type Stats
35+
EVENT_CONT = 'Cont' # Event Type continue
36+
EVENT_END = 'End' # Event Type is End
37+
EVENT_CONTENT_TYPE = "text/xml" # Event content xml type
38+
EVENT = 'event' # Message Type is event
39+
ERROR = 'error' # Message Type is error
40+
41+
def calculate_crc(value):
42+
'''
43+
Returns the CRC using crc32
44+
'''
45+
return crc32(value) & 0xffffffff
46+
47+
def validate_crc(current_value, expected_value):
48+
'''
49+
Validate through CRC check
50+
'''
51+
crc_current = calculate_crc(current_value)
52+
crc_expected = byte_int(expected_value)
53+
if crc_current == crc_expected:
54+
return True
55+
return False
56+
57+
def byte_int(data_bytes):
58+
'''
59+
Convert bytes to big-endian integer
60+
'''
61+
return int(codecs.encode(data_bytes, 'hex'), 16)

minio/select_object_options.py renamed to minio/select/options.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
# limitations under the License.
1616

1717
"""
18+
minio.select.options
19+
~~~~~~~~~~~~~~~
1820
19-
This module creates the request for Select
21+
This module implements the SelectOption definition for SelectObject API.
2022
2123
:copyright: (c) 2019 by MinIO, Inc.
2224
:license: Apache 2.0, see LICENSE for more details.
2325
2426
"""
25-
from .helpers import (SQL)
2627

28+
from .helpers import (SQL)
2729

2830
class CSVInput:
2931
"""
@@ -41,7 +43,6 @@ def __init__(self, FileHeaderInfo=None, RecordDelimiter="\n",
4143
self.Comments = Comments
4244
self.AllowQuotedRecordDelimiter = AllowQuotedRecordDelimiter
4345

44-
4546
class JSONInput:
4647
"""
4748
JSONInput: Input format as JSON.

0 commit comments

Comments
 (0)