-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update abstractdriver.py #55
Open
vsarathy1
wants to merge
1
commit into
main
Choose a base branch
from
ch2_schemas_and_mongodbdriver_changes-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,119 @@ def formatConfig(self, config): | |
ret += "\n\n# %s\n%-20s = %s" % (desc, name, default) | ||
return (ret) | ||
|
||
def getOneDoc(self, tableName, tuple, generateKey=False): | ||
if self.schema == constants.CH2_DRIVER_SCHEMA["CH2"]: | ||
return self.getOneCH2Doc(tableName, tuple, generateKey) | ||
else: | ||
return self.getOneCH2PPDoc(tableName, tuple, generateKey) | ||
|
||
def getOneCH2Doc(self, tableName, tuple, generateKey): | ||
columns = constants.CH2_TABLE_COLUMNS[tableName] | ||
key = "" | ||
if generateKey: | ||
for l, k in enumerate(constants.KEYNAMES[tableName]): | ||
if l == 0: | ||
key = str(tuple[k]) | ||
else: | ||
key = key + '.' + str(tuple[k]) | ||
Comment on lines
+76
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: we can write this perhaps more simply as
Same in |
||
val = {} | ||
for l, v in enumerate(tuple): | ||
v1 = tuple[l] | ||
if tableName == constants.TABLENAME_ORDERS and columns[l] == "o_orderline": | ||
v1 = [] | ||
for olv in v: | ||
v1.append(self.genNestedTuple(olv, constants.TABLENAME_ORDERLINE)) | ||
elif (tableName == constants.TABLENAME_ITEM and columns[l] == "i_categories" or | ||
tableName == constants.TABLENAME_CUSTOMER and columns[l] == "c_item_categories"): | ||
continue | ||
elif tableName == constants.TABLENAME_CUSTOMER and columns[l] == "c_extra": | ||
for i in range(0, self.customerExtraFields): | ||
val[columns[l]+"_"+str(format(i+1, "03d"))] = v1[i] | ||
continue | ||
elif tableName == constants.TABLENAME_ORDERS and columns[l] == "o_extra": | ||
for i in range(0, self.ordersExtraFields): | ||
val[columns[l]+"_"+str(format(i+1, "03d"))] = v1[i] | ||
continue | ||
elif tableName == constants.TABLENAME_ITEM and columns[l] == "i_extra": | ||
for i in range(0, self.itemExtraFields): | ||
val[columns[l]+"_"+str(format(i+1, "03d"))] = v1[i] | ||
continue | ||
elif isinstance(v1,(datetime)): | ||
v1 = str(v1) | ||
val[columns[l]] = v1 | ||
|
||
return key, val | ||
|
||
def getOneCH2PPDoc(self, tableName, tuple, generateKey): | ||
columns = constants.CH2PP_TABLE_COLUMNS[tableName] | ||
key = "" | ||
if generateKey: | ||
for l, k in enumerate(constants.KEYNAMES[tableName]): | ||
if l == 0: | ||
key = str(tuple[k]) | ||
else: | ||
key = key + '.' + str(tuple[k]) | ||
val = {} | ||
for l, v in enumerate(tuple): | ||
v1 = tuple[l] | ||
if isinstance(v1,(datetime)): | ||
v1 = str(v1) | ||
elif tableName == constants.TABLENAME_ORDERS and columns[l] == "o_orderline": | ||
v1 = [] | ||
for olv in v: | ||
v1.append(self.genNestedTuple(olv, constants.TABLENAME_ORDERLINE)) | ||
elif (self.schema == constants.CH2_DRIVER_SCHEMA["CH2P"] and | ||
(tableName == constants.TABLENAME_ITEM and columns[l] == "i_categories" or | ||
tableName == constants.TABLENAME_CUSTOMER and columns[l] == "c_item_categories")): | ||
continue | ||
elif tableName == constants.TABLENAME_WAREHOUSE and columns[l] == "w_address": | ||
v1 = self.genNestedTuple(v, constants.TABLENAME_WAREHOUSE_ADDRESS) | ||
elif tableName == constants.TABLENAME_DISTRICT and columns[l] == "d_address": | ||
v1 = self.genNestedTuple(v, constants.TABLENAME_DISTRICT_ADDRESS) | ||
elif tableName == constants.TABLENAME_SUPPLIER and columns[l] == "su_address": | ||
v1 = self.genNestedTuple(v, constants.TABLENAME_SUPPLIER_ADDRESS) | ||
elif tableName == constants.TABLENAME_CUSTOMER: | ||
if columns[l] == "c_name": | ||
v1 = self.genNestedTuple(v, constants.TABLENAME_CUSTOMER_NAME) | ||
elif columns[l] == "c_extra": | ||
for i in range(0, self.customerExtraFields): | ||
val[columns[l]+"_"+str(format(i+1, "03d"))] = v1[i] | ||
continue | ||
elif columns[l] == "c_addresses": | ||
v1 = [] | ||
for clv in v: | ||
v1.append(self.genNestedTuple(clv, constants.TABLENAME_CUSTOMER_ADDRESSES)) | ||
if self.schema == constants.CH2_DRIVER_SCHEMA["CH2P"]: | ||
break # Load only one customer address for CH2P | ||
elif columns[l] == "c_phones": | ||
v1 = [] | ||
for clv in v: | ||
v1.append(self.genNestedTuple(clv, constants.TABLENAME_CUSTOMER_PHONES)) | ||
if self.schema == constants.CH2_DRIVER_SCHEMA["CH2P"]: | ||
break # Load only one customer phone for CH2P | ||
elif tableName == constants.TABLENAME_ORDERS and columns[l] == "o_extra": | ||
for i in range(0, self.ordersExtraFields): | ||
val[columns[l]+"_"+str(format(i+1, "03d"))] = v1[i] | ||
continue | ||
elif tableName == constants.TABLENAME_ITEM and columns[l] == "i_extra": | ||
for i in range(0, self.itemExtraFields): | ||
val[columns[l]+"_"+str(format(i+1, "03d"))] = v1[i] | ||
continue | ||
val[columns[l]] = v1 | ||
return key, val | ||
|
||
def genNestedTuple(self, tuple, tableName): | ||
if self.schema == constants.CH2_DRIVER_SCHEMA["CH2"]: | ||
columns = constants.CH2_TABLE_COLUMNS[tableName] | ||
else: | ||
columns = constants.CH2PP_TABLE_COLUMNS[tableName] | ||
rval = {} | ||
for l, v in enumerate(tuple): | ||
if isinstance(v,(datetime)): | ||
v = str(v) | ||
rval[columns[l]] = v | ||
return rval | ||
|
||
def loadStart(self): | ||
"""Optional callback to indicate to the driver that the data loading phase is about to begin.""" | ||
return None | ||
|
@@ -168,3 +281,4 @@ def doStockLevel(self, params): | |
""" | ||
raise NotImplementedError("%s does not implement doStockLevel" % (self.driver_name)) | ||
## CLASS | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: can we rename the parameter
tuple
so that it doesn't shadow the Python built-intuple
?Maybe something like
doc_tuple
orfield_values
?Same goes for
getOneCH2Doc
,getOneCH2PPDoc
,genNestedTuple
etc.