Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
olapy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
olapy
Commits
732b4d9d
Commit
732b4d9d
authored
Jun 08, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimization 1 (free ram space after loading page)
parent
0f8cb74f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
3 deletions
+28
-3
olapy/core/mdx/executor/execute_db.py
olapy/core/mdx/executor/execute_db.py
+28
-3
No files found.
olapy/core/mdx/executor/execute_db.py
View file @
732b4d9d
from
__future__
import
absolute_import
,
division
,
print_function
from
__future__
import
absolute_import
,
division
,
print_function
from
sqlalchemy
import
inspect
from
sqlalchemy
import
inspect
import
pandas
as
pd
from
..tools.mem_bench
import
memory_usage
from
..tools.mem_bench
import
memory_usage
from
..tools.connection
import
MyDB
from
..tools.connection
import
MyDB
import
pandas.io.sql
as
psql
import
pandas.io.sql
as
psql
...
@@ -19,12 +19,37 @@ def _load_tables_db(executer_instance):
...
@@ -19,12 +19,37 @@ def _load_tables_db(executer_instance):
memory_usage
(
"1 - before executing query //// _load_tables_db"
)
memory_usage
(
"1 - before executing query //// _load_tables_db"
)
for
table_name
in
inspector
.
get_table_names
():
for
table_name
in
inspector
.
get_table_names
():
value
=
psql
.
read_sql_query
(
'SELECT * FROM "{0}"'
.
format
(
table_name
),
db
.
engine
)
# value = psql.read_sql_query(
# 'SELECT * FROM "{0}"'.format(table_name), db.engine)
# results = db.engine.execute('SELECT * FROM "{0}"'.format(table_name))
results
=
(
db
.
engine
.
execution_options
(
stream_results
=
True
)
.
execute
(
'SELECT * FROM "{0}"'
.
format
(
table_name
)))
# Fetch all the results of the query
fetchall
=
results
.
fetchall
()
# fetchall = results.fetchone()
value
=
pd
.
DataFrame
(
fetchall
,
columns
=
results
.
keys
())
tables
[
table_name
]
=
value
[[
tables
[
table_name
]
=
value
[[
col
for
col
in
value
.
columns
if
col
.
lower
()[
-
3
:]
!=
'_id'
col
for
col
in
value
.
columns
if
col
.
lower
()[
-
3
:]
!=
'_id'
]]
]]
# tables = {}
# db = MyDB(db_config_file_path=executer_instance.DATA_FOLDER, db=executer_instance.cube)
# # inspector = inspect(db.engine)
# cursor = db.engine.cursor()
# cursor.execute("""SELECT table_name FROM information_schema.tables
# WHERE table_schema = 'public'""")
#
# for table_name in cursor.fetchall():
# value = psql.read_sql_query(
# 'SELECT * FROM "{0}" '.format(table_name[0]), db.engine)
#
# tables[table_name[0]] = value[[
# col for col in value.columns if col.lower()[-3:] != '_id'
# ]]
memory_usage
(
"2 - after query, before fetchall /////// _load_tables_db"
)
memory_usage
(
"2 - after query, before fetchall /////// _load_tables_db"
)
return
tables
return
tables
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment