<commit_before># Copyright 2013 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Mapreduce to cache datastore entities for lists."""

from google.appengine.ext import ndb

from mapreduce import context
from mapreduce import base_handler
from mapreduce import mapreduce_pipeline

import datetime

import json

import pickle


NO_OF_SHARDS = 4


def mapProcess(entity):
  # TODO: (Aruna) Fix this import
  from melange.utils import lists

  ctx = context.get()
  params = ctx.mapreduce_spec.mapper.params

  list_id = params['list_id']
  col_funcs = [(c.name, c.getValue) for c in lists.getList(list_id).columns]
  query_pickle = params['query_pickle']

  query = pickle.loads(query_pickle)
  data_id = lists.getDataId(query)

  if(query.filter('__key__', entity.key()).get()):
    item = json.dumps(lists.toListItemDict(entity, col_funcs))

    yield (data_id, item)


def reduceProcess(data_id, entities):
  # TODO: (Aruna) Fix these import
  from melange.logic import cached_list
  from melange.utils import lists

  ctx = context.get()
  params = ctx.mapreduce_spec.mapper.params

  list_id = params['list_id']<commit_msg>When creating list item 'col_id' is used instead of 'name' as the key of the dict.<commit_after># Copyright 2013 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Mapreduce to cache datastore entities for lists."""

from google.appengine.ext import ndb

from mapreduce import context
from mapreduce import base_handler
from mapreduce import mapreduce_pipeline

import datetime

import json

import pickle


NO_OF_SHARDS = 4


def mapProcess(entity):
  # TODO: (Aruna) Fix this import
  from melange.utils import lists

  ctx = context.get()
  params = ctx.mapreduce_spec.mapper.params

  list_id = params['list_id']
  col_funcs = [(c.col_id, c.getValue) for c in lists.getList(list_id).columns]
  query_pickle = params['query_pickle']

  query = pickle.loads(query_pickle)
  data_id = lists.getDataId(query)

  if(query.filter('__key__', entity.key()).get()):
    item = json.dumps(lists.toListItemDict(entity, col_funcs))

    yield (data_id, item)


def reduceProcess(data_id, entities):
  # TODO: (Aruna) Fix these import
  from melange.logic import cached_list
  from melange.utils import lists

  ctx = context.get()
  params = ctx.mapreduce_spec.mapper.params

  list_id = params['list_id']
{'fraction_non_alphanumeric': 0.08841917237272998, 'fraction_numerical': 0.005358737719559393, 'mean_word_length': 4.463414634146342, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '113374', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1003, 'n_words': 364}