Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions cloudquery/sdk/internal/memdb/memdb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cloudquery.sdk import plugin
from cloudquery.sdk import message
from cloudquery.sdk import schema
from typing import List, Generator, Any, Dict
from typing import List, Generator, Dict
import pyarrow as pa

NAME = "memdb"
Expand All @@ -24,13 +24,13 @@ def sync(
for table, record in self._db.items():
yield message.SyncInsertMessage(record)

def write(self, msg_iterator: Generator[message.WriteMessage, None, None]) -> None:
for msg in msg_iterator:
if type(msg) == message.WriteMigrateTableMessage:
def write(self, writer: Generator[message.WriteMessage, None, None]) -> None:
for msg in writer:
if isinstance(msg, message.WriteMigrateTableMessage):
if msg.table.name not in self._db:
self._db[msg.table.name] = msg.table
self._tables[msg.table.name] = msg.table
elif type(msg) == message.WriteInsertMessage:
elif isinstance(msg, message.WriteInsertMessage):
table = schema.Table.from_arrow_schema(msg.record.schema)
self._db[table.name] = msg.record
else:
Expand Down
8 changes: 4 additions & 4 deletions cloudquery/sdk/scalar/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Binary(Scalar):
def __eq__(self, scalar: Scalar) -> bool:
if scalar is None:
return False
if type(scalar) == Binary:
if isinstance(scalar, Binary):
return self._value == scalar._value and self._valid == scalar._valid
return False

Expand All @@ -23,13 +23,13 @@ def set(self, value: any):
self._value = value.value
return

if type(value) == bytes:
if isinstance(value, bytes):
self._valid = True
self._value = value
elif type(value) == str:
elif isinstance(value, str):
self._valid = True
self._value = value.encode()
else:
raise ScalarInvalidTypeError(
"Invalid type {} for Binary scalar".format(type(value))
f"Invalid type {type(value)} for Binary scalar"
)
14 changes: 6 additions & 8 deletions cloudquery/sdk/scalar/bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ def parse_string_to_bool(input_string):

if lower_input in true_strings:
return True
elif lower_input in false_strings:
if lower_input in false_strings:
return False
else:
raise ScalarInvalidTypeError("Invalid boolean string: {}".format(input_string))
raise ScalarInvalidTypeError(f"Invalid boolean string: {input_string}")


class Bool(Scalar):
def __eq__(self, scalar: Scalar) -> bool:
if scalar is None:
return False
if type(scalar) == Bool:
if isinstance(scalar, Bool):
return self._value == scalar._value and self._valid == scalar._valid
return False

Expand All @@ -38,13 +38,11 @@ def set(self, value: Any):
self._value = value.value
return

if type(value) == bool:
if isinstance(value, bool):
self._value = value
elif type(value) == str:
elif isinstance(value, str):
self._value = parse_string_to_bool(value)
else:
raise ScalarInvalidTypeError(
"Invalid type {} for Bool scalar".format(type(value))
)
raise ScalarInvalidTypeError(f"Invalid type {type(value)} for Bool scalar")

self._valid = True
10 changes: 5 additions & 5 deletions cloudquery/sdk/scalar/date32.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Date32(Scalar):
def __eq__(self, scalar: Scalar) -> bool:
if scalar is None:
return False
if type(scalar) == Date32:
if isinstance(scalar, Date32):
return self._value == scalar._value and self._valid == scalar._valid
return False

Expand All @@ -25,15 +25,15 @@ def set(self, value: Any):
self._value = value.value
return

if type(value) == datetime:
if isinstance(value, datetime):
self._value = value
elif type(value) == str:
elif isinstance(value, str):
self._value = datetime.strptime(value, "%Y-%m-%d")
elif type(value) == time:
elif isinstance(value, time):
self._value = datetime.combine(datetime.today(), value)
else:
raise ScalarInvalidTypeError(
"Invalid type {} for Date32 scalar".format(type(value))
f"Invalid type {type(value)} for Date32 scalar"
)

self._valid = True
10 changes: 5 additions & 5 deletions cloudquery/sdk/scalar/date64.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Date64(Scalar):
def __eq__(self, scalar: Scalar) -> bool:
if scalar is None:
return False
if type(scalar) == Date64:
if isinstance(scalar, Date64):
return self._value == scalar._value and self._valid == scalar._valid
return False

Expand All @@ -25,15 +25,15 @@ def set(self, value: Any):
self._value = value.value
return

if type(value) == datetime:
if isinstance(value, datetime):
self._value = value
elif type(value) == str:
elif isinstance(value, str):
self._value = datetime.strptime(value, "%Y-%m-%d")
elif type(value) == time:
elif isinstance(value, time):
self._value = datetime.combine(datetime.today(), value)
else:
raise ScalarInvalidTypeError(
"Invalid type {} for Date64 scalar".format(type(value))
f"Invalid type {type(value)} for Date64 scalar"
)

self._valid = True
16 changes: 8 additions & 8 deletions cloudquery/sdk/scalar/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __init__(self, valid: bool = False, value: any = None, bitwidth: int = 64):
def __eq__(self, scalar: Scalar) -> bool:
if scalar is None:
return False
if type(scalar) == Float and self._bitwidth == scalar.bitwidth:
if isinstance(scalar, Float) and self._bitwidth == scalar.bitwidth:
return self._value == scalar._value and self._valid == scalar._valid
return False

Expand All @@ -31,19 +31,19 @@ def set(self, value: any):
self._value = value.value
return

if type(value) == int:
if isinstance(value, int):
self._value = float(value)
elif type(value) == float:
elif isinstance(value, float):
self._value = value
elif type(value) == str:
elif isinstance(value, str):
try:
self._value = float(value)
except ValueError:
except ValueError as e:
raise ScalarInvalidTypeError(
"Invalid value for Float{} scalar".format(self._bitwidth)
)
f"Invalid value for Float{self._bitwidth} scalar"
) from e
else:
raise ScalarInvalidTypeError(
"Invalid type {} for Float{} scalar".format(type(value), self._bitwidth)
f"Invalid type {type(value)} for Float{self._bitwidth} scalar"
)
self._valid = True
14 changes: 7 additions & 7 deletions cloudquery/sdk/scalar/int.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, valid: bool = False, value: any = None, bitwidth: int = 64):
def __eq__(self, scalar: Scalar) -> bool:
if scalar is None:
return False
if type(scalar) == Int and self._bitwidth == scalar.bitwidth:
if isinstance(scalar, Int) and self._bitwidth == scalar.bitwidth:
return self._value == scalar._value and self._valid == scalar._valid
return False

Expand All @@ -33,24 +33,24 @@ def set(self, value: any):
self._value = value.value
return

if type(value) == int:
if isinstance(value, int):
val = value
elif type(value) == float:
elif isinstance(value, float):
val = int(value)
elif type(value) == str:
elif isinstance(value, str):
try:
val = int(value)
except ValueError as e:
raise ScalarInvalidTypeError(
"Invalid type for Int{} scalar".format(self._bitwidth)
f"Invalid type for Int{self._bitwidth} scalar"
) from e
else:
raise ScalarInvalidTypeError(
"Invalid type {} for Int{} scalar".format(type(value), self._bitwidth)
f"Invalid type {type(value)} for Int{self._bitwidth} scalar"
)
if val < self._min or val >= self._max:
raise ScalarInvalidTypeError(
"Invalid Int{} scalar with value {}".format(self._bitwidth, val)
f"Invalid Int{self._bitwidth} scalar with value {val}"
)
self._value = val
self._valid = True
4 changes: 2 additions & 2 deletions cloudquery/sdk/scalar/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class JSON(Scalar):
def __eq__(self, scalar: Scalar) -> bool:
if scalar is None:
return False
if type(scalar) == JSON:
if isinstance(scalar, JSON):
return self._value == scalar._value and self._valid == scalar._valid
return False

Expand All @@ -18,7 +18,7 @@ def set(self, value: any):
if value is None:
return

if type(value) == str or type(value) == bytes:
if isinstance(value, (str, bytes)):
# test if it is a valid json
json.loads(value)
self._value = value
Expand Down
26 changes: 11 additions & 15 deletions cloudquery/sdk/scalar/list.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cloudquery.sdk.scalar import Scalar, ScalarInvalidTypeError
from .scalar import NULL_VALUE
from .vector import Vector
from typing import Any, Type, Union
from typing import Any, Type


class List(Scalar):
Expand All @@ -10,12 +10,8 @@ def __init__(self, scalar_type: Type[Scalar]):
self._value = Vector(scalar_type)
self._type = scalar_type

def __eq__(self, other: Union[None, "List"]) -> bool:
if other is None:
return False
if type(self) != type(other):
return False
if self._valid != other._valid:
def __eq__(self, other: "List") -> bool:
if (not isinstance(other, self.__class__)) or self._valid != other._valid:
return False
return self._value == other._value

Expand All @@ -27,29 +23,29 @@ def type(self):
def value(self):
return self._value

def set(self, val: Any):
if val is None:
def set(self, value: Any):
if value is None:
self._valid = False
self._value = Vector()
return

if isinstance(val, Scalar) and type(val) == self._type:
if not val.is_valid:
if isinstance(value, self._type):
if not value.is_valid:
self._valid = False
self._value = Vector()
return
return self.set([val.value])
return self.set([value.value])

if isinstance(val, (list, tuple)):
if isinstance(value, (list, tuple)):
self._value = Vector()
for item in val:
for item in value:
scalar = self._type()
scalar.set(item)
self._value.append(scalar)
self._valid = True
return

raise ScalarInvalidTypeError("Invalid type {} for List".format(type(val)))
raise ScalarInvalidTypeError(f"Invalid type {type(value)} for List")

def __str__(self) -> str:
if not self._valid:
Expand Down
Loading