Skip to content

Commit 001f422

Browse files
authored
Releases v0.12.4.1 (#299)
1 parent 46af1f9 commit 001f422

File tree

7 files changed

+55
-19
lines changed

7 files changed

+55
-19
lines changed

odps/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version_info = (0, 12, 4)
15+
version_info = (0, 12, 4, 1)
1616
_num_index = max(idx if isinstance(v, int) else 0 for idx, v in enumerate(version_info))
1717
__version__ = ".".join(map(str, version_info[: _num_index + 1])) + "".join(
1818
version_info[_num_index + 1 :]

odps/accounts.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939

4040

4141
def _get_v4_signature_prefix():
42-
if options.signature_prefix is not None:
43-
return options.signature_prefix
42+
opt_prefix = options.signature_prefix
43+
if opt_prefix is not None:
44+
return opt_prefix
4445
return DEFAULT_SIGNATURE_PREFIX
4546

4647

@@ -558,6 +559,7 @@ def sign_request(self, req, endpoint, region_name=None):
558559
class CredentialProviderAccount(StsAccount):
559560
def __init__(self, credential_provider):
560561
self.provider = credential_provider
562+
self._lock = threading.Lock()
561563
super(CredentialProviderAccount, self).__init__(None, None, None)
562564

563565
def _refresh_credential(self):
@@ -566,15 +568,29 @@ def _refresh_credential(self):
566568
except:
567569
credential = self.provider.get_credentials()
568570

569-
self.access_id = credential.get_access_key_id()
570-
self.secret_access_key = credential.get_access_key_secret()
571-
self.sts_token = credential.get_security_token()
571+
access_id = credential.get_access_key_id()
572+
secret_access_key = credential.get_access_key_secret()
573+
sts_token = credential.get_security_token()
574+
575+
with self._lock:
576+
if self.access_id and access_id == self.access_id:
577+
return
578+
579+
# invalidate signature date only when token changed
580+
self._last_signature_date = None
581+
582+
self.access_id = access_id
583+
self.secret_access_key = secret_access_key
584+
self.sts_token = sts_token
572585

573586
def sign_request(self, req, endpoint, region_name=None):
574587
utils.call_with_retry(self._refresh_credential)
575-
return super(CredentialProviderAccount, self).sign_request(
576-
req, endpoint, region_name=region_name
577-
)
588+
589+
with self._lock:
590+
# need to lock to make sure keys are consistent
591+
return super(CredentialProviderAccount, self).sign_request(
592+
req, endpoint, region_name=region_name
593+
)
578594

579595

580596
def from_environments():

odps/models/session/v1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ def _check_is_select(sql_statement):
221221
RuntimeWarning,
222222
)
223223
return False
224-
return splited[-1].lower().strip(" \t\r\n(").startswith("select")
224+
striped = splited[-1].lower().strip(" \t\r\n(")
225+
return striped.startswith("select") or striped.startswith("with")
225226

226227
def _create_internal_instance(self, task=None):
227228
project_name = self._project.name

odps/models/table.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ def open_writer(
11131113

11141114
if partition and not isinstance(partition, odps_types.PartitionSpec):
11151115
partition = odps_types.PartitionSpec(partition)
1116-
if create_partition and not self.exist_partition(create_partition):
1116+
if create_partition and not self.exist_partition(partition):
11171117
self.create_partition(partition, if_not_exists=True)
11181118

11191119
tunnel = self._create_table_tunnel(endpoint=endpoint, quota_name=quota_name)
@@ -1269,7 +1269,7 @@ def partitions(self):
12691269

12701270
@utils.with_wait_argument
12711271
def create_partition(
1272-
self, partition_spec, if_not_exists=False, async_=False, hints=None
1272+
self, partition_spec, if_not_exists=False, async_=False, hints=None, **inst_kw
12731273
):
12741274
"""
12751275
Create a partition within the table.
@@ -1282,12 +1282,16 @@ def create_partition(
12821282
:rtype: odps.models.partition.Partition
12831283
"""
12841284
return self.partitions.create(
1285-
partition_spec, if_not_exists=if_not_exists, hints=hints, async_=async_
1285+
partition_spec,
1286+
if_not_exists=if_not_exists,
1287+
hints=hints,
1288+
async_=async_,
1289+
**inst_kw
12861290
)
12871291

12881292
@utils.with_wait_argument
12891293
def delete_partition(
1290-
self, partition_spec, if_exists=False, async_=False, hints=None
1294+
self, partition_spec, if_exists=False, async_=False, hints=None, **inst_kw
12911295
):
12921296
"""
12931297
Delete a partition within the table.
@@ -1298,7 +1302,7 @@ def delete_partition(
12981302
:param async_:
12991303
"""
13001304
return self.partitions.delete(
1301-
partition_spec, if_exists=if_exists, hints=hints, async_=async_
1305+
partition_spec, if_exists=if_exists, hints=hints, async_=async_, **inst_kw
13021306
)
13031307

13041308
def exist_partition(self, partition_spec):

odps/models/tableio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ def _format_raw_sql(fmt, args):
15501550
),
15511551
)
15521552
odps.execute_sql(sql_stmt, **sql_kwargs)
1553-
tmp_schema = odps.get_table(temp_table_name).table_schema
1553+
tmp_schema = odps.get_table(temp_table_name, schema=schema).table_schema
15541554
out_table_schema = cls._resolve_schema(
15551555
data_schema=tmp_schema,
15561556
partition=partition,
@@ -1581,7 +1581,7 @@ def _format_raw_sql(fmt, args):
15811581
partition=partition,
15821582
)
15831583

1584-
temp_table = odps.get_table(temp_table_name)
1584+
temp_table = odps.get_table(temp_table_name, schema=schema)
15851585
union_cols, diff_cols = cls._calc_schema_diff(
15861586
temp_table.table_schema,
15871587
target_table.table_schema,

odps/models/tables.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ def create(
133133
**kw
134134
):
135135
project_name = self._parent.project.name
136+
137+
# pass kwargs for instance creation to _run_table_sql
138+
inst_kw = {}
139+
for key in (
140+
"instance_project",
141+
"priority",
142+
"running_cluster",
143+
"unique_identifier_id",
144+
):
145+
if key in kw:
146+
inst_kw[key] = kw.pop(key)
147+
136148
schema_name = self._get_schema_name()
137149
sql = Table.gen_create_table_sql(
138150
table_name,
@@ -152,7 +164,7 @@ def create(
152164
if storage_tier:
153165
hints["odps.tiered.storage.enable"] = "true"
154166
instance = self._run_table_sql(
155-
sql, task_name="SQLCreateTableTask", hints=hints, wait=not async_
167+
sql, task_name="SQLCreateTableTask", hints=hints, wait=not async_, **inst_kw
156168
)
157169
if not async_:
158170
return self[table_name]

odps/types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def __hash__(self):
327327
def __eq__(self, other):
328328
if not isinstance(other, Schema):
329329
return False
330-
return self.names == other.names and self.types == self.types
330+
return self.names == other.names and self.types == other.types
331331

332332
def get_type(self, name):
333333
return self.types[self._name_indexes[utils.to_lower_str(name)]]
@@ -908,6 +908,9 @@ def can_implicit_cast(self, other):
908908
def can_explicit_cast(self, other):
909909
return self.can_implicit_cast(other)
910910

911+
def __reduce__(self):
912+
return validate_data_type, (str(self),)
913+
911914
def validate_value(self, val, max_field_size=None):
912915
# directly return True means without checking
913916
return True

0 commit comments

Comments
 (0)