Skip to content

Commit

Permalink
parser debug
Browse files Browse the repository at this point in the history
  • Loading branch information
esedor committed Oct 11, 2013
1 parent 65eb8f9 commit 468a1a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 8 additions & 4 deletions dex/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class QueryAnalyzer:
def __init__(self, check_indexes):
self._internal_map = {}
self._check_indexes = check_indexes
self._index_cache_connection = None

############################################################################
def generate_query_report(self, db_uri, parsed_query, db_name, collection_name):
Expand All @@ -54,6 +55,7 @@ def generate_query_report(self, db_uri, parsed_query, db_name, collection_name):
db_name,
collection_name)


query_analysis = self._generate_query_analysis(parsed_query,
db_name,
collection_name)
Expand Down Expand Up @@ -95,10 +97,12 @@ def _ensure_index_cache(self, db_uri, db_name, collection_name):
if collection_name not in self._internal_map[db_name]:
indexes = []
try:
connection = pymongo.MongoClient(db_uri,
document_class=OrderedDict,
read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED)
db = connection[db_name]
if self._index_cache_connection is None:
self._index_cache_connection = pymongo.MongoClient(db_uri,
document_class=OrderedDict,
read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED)

db = self._index_cache_connection[db_name]
indexes = db[collection_name].index_information()
except:
warning = 'Warning: unable to connect to ' + db_uri + "\n"
Expand Down
9 changes: 2 additions & 7 deletions dex/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,7 @@ def handle(self, input):
class QueryLineHandler:
########################################################################
def parse_query(self, extracted_query):
yaml_query = yamlfy(extracted_query)

if '$query' not in yaml_query:
return OrderedDict([('$query', yaml_query)])
else:
return yaml_query
return yamlfy(extracted_query)

def parse_line_stats(self, stat_string):
line_stats = {}
Expand Down Expand Up @@ -289,7 +284,7 @@ def __init__(self):
def handle(self, input):
match = self._rx.match(input)
if match is not None:
parsed = yamlfy(match.group('query'))
parsed = self.parse_query(match.group('query'))
if parsed is not None:
result = OrderedDict()
result['stats'] = self.parse_line_stats(match.group('stats'))
Expand Down

0 comments on commit 468a1a1

Please sign in to comment.