本文整理汇总了Python中pyLibrary.dot.wrap函数的典型用法代码示例。如果您正苦于以下问题:Python wrap函数的具体用法?Python wrap怎么用?Python wrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wrap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(
self,
host,
user,
password,
table,
meta, # REDSHIFT COPY COMMAND REQUIRES A BUCKET TO HOLD PARAMETERS
database=None,
port=5439,
settings=None
):
self.settings = settings
self.db = Redshift(settings)
INDEX_CACHE[settings.table] = wrap({"name":settings.table}) # HACK TO GET parse_columns TO WORK
columns = parse_columns(settings.table, settings.mapping.test_result.properties)
nested = [c.name for c in columns if c.type == "nested"]
self.columns = wrap([c for c in columns if c.type not in ["object"] and not any(c.name.startswith(n+".") for n in nested)])
try:
self.db.execute("""
CREATE TABLE {{table_name}} (
"_id" character varying UNIQUE,
{{columns}}
)""", {
"table_name": self.db.quote_column(settings.table),
"columns": SQL(",\n".join(self.db.quote_column(c.name) + " " + self.db.es_type2pg_type(c.type) for c in self.columns))
}, retry=False)
except Exception, e:
if "already exists" in e:
Log.alert("Table {{table}} exists in Redshift", table= settings.table)
else:
Log.error("Could not make table", e)
开发者ID:klahnakoski,项目名称:Activedata-ETL,代码行数:32,代码来源:redshift.py
示例2: groupby
def groupby(data, keys=None, size=None, min_size=None, max_size=None, contiguous=False):
"""
return list of (keys, values) pairs where
group by the set of keys
values IS LIST OF ALL data that has those keys
contiguous - MAINTAIN THE ORDER OF THE DATA, STARTING THE NEW GROUP WHEN THE SELECTOR CHANGES
"""
if size != None or min_size != None or max_size != None:
if size != None:
max_size = size
return groupby_min_max_size(data, min_size=min_size, max_size=max_size)
if isinstance(data, Container):
return data.groupby(keys)
try:
keys = listwrap(keys)
get_key = jx_expression_to_function(keys)
if not contiguous:
data = sorted(data, key=get_key)
return ((wrap({k: v for k, v in zip(keys, g)}), wrap(v)) for g, v in itertools.groupby(data, get_key))
except Exception, e:
Log.error("Problem grouping", e)
开发者ID:klahnakoski,项目名称:MoDataSubmission,代码行数:25,代码来源:group_by.py
示例3: convert
def convert(self, expr):
"""
ADD THE ".$value" SUFFIX TO ALL VARIABLES
"""
if expr is True or expr == None or expr is False:
return expr
elif Math.is_number(expr):
return expr
elif expr == ".":
return "."
elif is_keyword(expr):
#TODO: LOOKUP SCHEMA AND ADD ALL COLUMNS WITH THIS PREFIX
return expr + ".$value"
elif isinstance(expr, basestring):
Log.error("{{name|quote}} is not a valid variable name", name=expr)
elif isinstance(expr, Date):
return expr
elif isinstance(expr, Query):
return self._convert_query(expr)
elif isinstance(expr, Mapping):
if expr["from"]:
return self._convert_query(expr)
elif len(expr) >= 2:
#ASSUME WE HAVE A NAMED STRUCTURE, NOT AN EXPRESSION
return wrap({name: self.convert(value) for name, value in expr.items()})
else:
# ASSUME SINGLE-CLAUSE EXPRESSION
k, v = expr.items()[0]
return self.converter_map.get(k, self._convert_bop)(k, v)
elif isinstance(expr, (list, set, tuple)):
return wrap([self.convert(value) for value in expr])
开发者ID:klahnakoski,项目名称:MoDevETL,代码行数:31,代码来源:typed.py
示例4: __init__
def __init__(self, value):
self.scheme = None
self.host = None
self.port = None
self.path = ""
self.query = ""
self.fragment = ""
if value == None:
return
if not _convert:
_late_import()
if value.startswith("file://") or value.startswith("//"):
# urlparse DOES NOT WORK IN THESE CASES
scheme, suffix = value.split("//")
self.scheme = scheme.rstrip(":")
parse(self, suffix, 0, 1)
self.query = wrap(_convert.url_param2value(self.query))
self.fragment = self.fragment
else:
output = urlparse(value)
self.scheme = output.scheme
self.port = output.port
self.host = output.netloc.split(":")[0]
self.path = output.path
self.query = wrap(_convert.url_param2value(output.query))
self.fragment = output.fragment
开发者ID:klahnakoski,项目名称:MoDevETL,代码行数:29,代码来源:parsers.py
示例5: append_query
def append_query(self, es_query, start):
self.start = start
domain = self.domain
field = self.edge.value
if isinstance(field, Variable):
key = domain.key
if isinstance(key, (tuple, list)) and len(key)==1:
key = key[0]
include = [p[key] for p in domain.partitions]
if self.edge.allowNulls:
return wrap({"aggs": {
"_match": set_default({"terms": {
"field": field.var,
"size": self.limit,
"include": include
}}, es_query),
"_missing": set_default(
{"filter": {"or": [
field.missing().to_esfilter(),
{"not": {"terms": {field.var: include}}}
]}},
es_query
),
}})
else:
return wrap({"aggs": {
"_match": set_default({"terms": {
"field": field.var,
"size": self.limit,
"include": include
}}, es_query)
}})
else:
include = [p[domain.key] for p in domain.partitions]
if self.edge.allowNulls:
return wrap({"aggs": {
"_match": set_default({"terms": {
"script_field": field.to_ruby(),
"size": self.limit,
"include": include
}}, es_query),
"_missing": set_default(
{"filter": {"or": [
field.missing().to_esfilter(),
NotOp("not", InOp("in", [field, Literal("literal", include)])).to_esfilter()
]}},
es_query
),
}})
else:
return wrap({"aggs": {
"_match": set_default({"terms": {
"script_field": field.to_ruby(),
"size": self.limit,
"include": include
}}, es_query)
}})
开发者ID:klahnakoski,项目名称:esReplicate,代码行数:60,代码来源:decoders.py
示例6: __init__
def __init__(self, value):
if not _convert:
_late_import()
try:
self.scheme = None
self.host = None
self.port = None
self.path = ""
self.query = ""
self.fragment = ""
if value == None:
return
if value.startswith("file://") or value.startswith("//"):
# urlparse DOES NOT WORK IN THESE CASES
scheme, suffix = value.split("//")
self.scheme = scheme.rstrip(":")
parse(self, suffix, 0, 1)
self.query = wrap(_convert.url_param2value(self.query))
else:
output = urlparse(value)
self.scheme = output.scheme
self.port = output.port
self.host = output.netloc.split(":")[0]
self.path = output.path
self.query = wrap(_convert.url_param2value(output.query))
self.fragment = output.fragment
except Exception, e:
_Log.error("problem parsing {{value}} to URL", value=value, cause=e)
开发者ID:klahnakoski,项目名称:MoDataSubmission,代码行数:31,代码来源:parsers.py
示例7: convert
def convert(self, expr):
"""
EXPAND INSTANCES OF name TO value
"""
if expr is True or expr == None or expr is False:
return expr
elif Math.is_number(expr):
return expr
elif expr == ".":
return "."
elif is_keyword(expr):
return coalesce(self.dimensions[expr], expr)
elif isinstance(expr, basestring):
Log.error("{{name|quote}} is not a valid variable name", name=expr)
elif isinstance(expr, Date):
return expr
elif isinstance(expr, Query):
return self._convert_query(expr)
elif isinstance(expr, Mapping):
if expr["from"]:
return self._convert_query(expr)
elif len(expr) >= 2:
#ASSUME WE HAVE A NAMED STRUCTURE, NOT AN EXPRESSION
return wrap({name: self.convert(value) for name, value in expr.leaves()})
else:
# ASSUME SINGLE-CLAUSE EXPRESSION
k, v = expr.items()[0]
return converter_map.get(k, self._convert_bop)(self, k, v)
elif isinstance(expr, (list, set, tuple)):
return wrap([self.convert(value) for value in expr])
else:
return expr
开发者ID:klahnakoski,项目名称:MoDevETL,代码行数:32,代码来源:rename.py
示例8: es_query_template
def es_query_template(path):
"""
RETURN TEMPLATE AND PATH-TO-FILTER AS A 2-TUPLE
:param path:
:return:
"""
sub_path = split_field(path)[1:]
if sub_path:
f0 = {}
f1 = {}
output = wrap(
{
"filter": {
"and": [
f0,
{"nested": {"path": join_field(sub_path), "filter": f1, "inner_hits": {"size": 100000}}},
]
},
"from": 0,
"size": 0,
"sort": [],
}
)
return output, wrap([f0, f1])
else:
f0 = {}
output = wrap({"query": {"filtered": {"filter": f0}}, "from": 0, "size": 0, "sort": []})
return output, wrap([f0])
开发者ID:klahnakoski,项目名称:esReplicate,代码行数:29,代码来源:util.py
示例9: metas
def metas(self, prefix=None, limit=None, delimiter=None):
"""
RETURN THE METADATA DESCRIPTORS FOR EACH KEY
"""
keys = self.bucket.list(prefix=prefix, delimiter=delimiter)
if limit:
output = []
for i, k in enumerate(keys):
output.append({
"key": strip_extension(k.key),
"etag": convert.quote2string(k.etag),
"expiry_date": Date(k.expiry_date),
"last_modified": Date(k.last_modified)
})
if i >= limit:
break
return wrap(output)
output = [
{
"key": strip_extension(k.key),
"etag": convert.quote2string(k.etag),
"expiry_date": Date(k.expiry_date),
"last_modified": Date(k.last_modified)
}
for k in keys
]
return wrap(output)
开发者ID:klahnakoski,项目名称:MoTreeherder,代码行数:29,代码来源:s3.py
示例10: get
def get(url):
"""
USE json.net CONVENTIONS TO LINK TO INLINE OTHER JSON
"""
if not _Log:
_late_import()
if url.find("://") == -1:
_Log.error("{{url}} must have a prototcol (eg http://) declared", url=url)
base = URL("")
if url.startswith("file://") and url[7] != "/":
if os.sep=="\\":
base = URL("file:///" + os.getcwd().replace(os.sep, "/").rstrip("/") + "/.")
else:
base = URL("file://" + os.getcwd().rstrip("/") + "/.")
elif url[url.find("://") + 3] != "/":
_Log.error("{{url}} must be absolute", url=url)
phase1 = _replace_ref(wrap({"$ref": url}), base) # BLANK URL ONLY WORKS IF url IS ABSOLUTE
try:
phase2 = _replace_locals(phase1, [phase1])
return wrap(phase2)
except Exception, e:
_Log.error("problem replacing locals in\n{{phase1}}", phase1=phase1)
开发者ID:klahnakoski,项目名称:MoDataSubmission,代码行数:25,代码来源:ref.py
示例11: append_query
def append_query(self, es_query, start):
self.start = start
if not isinstance(self.edge.value, Variable):
script_field = self.edge.value.to_ruby()
missing = self.edge.value.missing().to_esfilter()
output = wrap(
{
"aggs": {
"_match": set_default(
{"terms": {"script_field": script_field, "size": self.domain.limit}}, es_query
),
"_missing": set_default({"filter": missing}, es_query),
}
}
)
return output
output = wrap(
{
"aggs": {
"_match": set_default(
{"terms": {"field": self.edge.value.var, "size": self.domain.limit}}, es_query
),
"_missing": set_default({"missing": {"field": self.edge.value}}, es_query),
}
}
)
return output
开发者ID:mozilla,项目名称:ChangeDetector,代码行数:30,代码来源:aggs.py
示例12: __getitem__
def __getitem__(self, key):
if key == None:
return Null
if key == ".":
output = _get(self, "_dict")
if isinstance(output, Mapping):
return self
else:
return output
if isinstance(key, str):
key = key.decode("utf8")
elif not isinstance(key, unicode):
from pyLibrary.debugs.logs import Log
Log.error("only string keys are supported")
d = _get(self, "_dict")
if key.find(".") >= 0:
seq = _split_field(key)
for n in seq:
if isinstance(d, NullType):
d = NullType(d, n) # OH DEAR, Null TREATS n AS PATH, NOT LITERAL
else:
d = _getdefault(d, n) # EVERYTHING ELSE TREATS n AS LITERAL
return wrap(d)
else:
o = d.get(key)
if o == None:
return NullType(d, key)
return wrap(o)
开发者ID:klahnakoski,项目名称:MoDataSubmission,代码行数:33,代码来源:dicts.py
示例13: _aggs_iterator
def _aggs_iterator(agg, d):
agg = drill(agg)
if d > 0:
for b in agg.get("_match", EMPTY).get("buckets", EMPTY_LIST):
parts[d] = wrap(b)
for a in _aggs_iterator(b, d - 1):
yield a
parts[d] = Null
for b in agg.get("_other", EMPTY).get("buckets", EMPTY_LIST):
for a in _aggs_iterator(b, d - 1):
yield a
b = drill(agg.get("_missing", EMPTY))
if b.get("doc_count"):
for a in _aggs_iterator(b, d - 1):
yield a
else:
for b in agg.get("_match", EMPTY).get("buckets", EMPTY_LIST):
parts[d] = wrap(b)
b = drill(b)
if b.get("doc_count"):
yield b
parts[d] = Null
for b in agg.get("_other", EMPTY).get("buckets", EMPTY_LIST):
b = drill(b)
if b.get("doc_count"):
yield b
b = drill(agg.get("_missing", EMPTY))
if b.get("doc_count"):
yield b
开发者ID:mozilla,项目名称:ChangeDetector,代码行数:30,代码来源:aggs.py
示例14: __init__
def __init__(self, host, index, alias=None, name=None, port=9200, settings=None):
global _elasticsearch
if hasattr(self, "settings"):
return
from pyLibrary.queries.containers.lists import ListContainer
from pyLibrary.env import elasticsearch as _elasticsearch
self.settings = settings
self.default_name = coalesce(name, alias, index)
self.default_es = _elasticsearch.Cluster(settings=settings)
self.todo = Queue("refresh metadata", max=100000, unique=True)
self.meta=Dict()
table_columns = metadata_tables()
column_columns = metadata_columns()
self.meta.tables = ListContainer("meta.tables", [], wrap({c.name: c for c in table_columns}))
self.meta.columns = ListContainer("meta.columns", [], wrap({c.name: c for c in column_columns}))
self.meta.columns.insert(column_columns)
self.meta.columns.insert(table_columns)
# TODO: fix monitor so it does not bring down ES
if ENABLE_META_SCAN:
self.worker = Thread.run("refresh metadata", self.monitor)
else:
self.worker = Thread.run("refresh metadata", self.not_monitor)
return
开发者ID:klahnakoski,项目名称:esReplicate,代码行数:26,代码来源:meta.py
示例15: append_query
def append_query(self, es_query, start):
self.start = start
if not isinstance(self.edge.value, Variable):
script_field = self.edge.value.to_ruby()
missing = self.edge.value.missing()
output = wrap(
{
"aggs": {
"_match": set_default(
{"terms": {"script_field": script_field, "size": self.domain.limit}}, es_query
),
"_missing": set_default({"filter": missing.to_esfilter()}, es_query) if missing else None,
}
}
)
return output
output = wrap(
{
"aggs": {
"_match": set_default(
{"terms": {"field": self.edge.value.var, "size": self.domain.limit}}, es_query
),
"_missing": set_default(
{"missing": {"field": self.edge.value}}, es_query
), # TODO: Use Expression.missing().esfilter() TO GET OPTIMIZED FILTER
}
}
)
return output
开发者ID:klahnakoski,项目名称:TestFailures,代码行数:32,代码来源:decoders.py
示例16: map
def map(self, map_):
def map_select(s, map_):
return set_default({"value": s.value.map(map_)}, s)
def map_edge(e, map_):
partitions = unwraplist([set_default({"where": p.where.map(map_)}, p) for p in e.domain.partitions])
domain = copy(e.domain)
domain.where = e.domain.where.map(map_)
domain.partitions = partitions
edge = copy(e)
edge.value = e.value.map(map_)
edge.domain = domain
if e.range:
edge.range.min = e.range.min.map(map_)
edge.range.max = e.range.max.map(map_)
return edge
return QueryOp(
"from",
frum=self.frum.map(map_),
select=wrap([map_select(s, map_) for s in listwrap(self.select)]),
edges=wrap([map_edge(e, map_) for e in self.edges]),
groupby=wrap([g.map(map_) for g in self.groupby]),
window=wrap([w.map(map_) for w in self.window]),
where=self.where.map(map_),
sort=wrap([map_select(s, map_) for s in listwrap(self.sort)]),
limit=self.limit,
format=self.format,
)
开发者ID:klahnakoski,项目名称:MoDataSubmission,代码行数:31,代码来源:query.py
示例17: search
def search(self, query):
query = wrap(query)
f = jx.get(query.query.filtered.filter)
filtered = wrap([{"_id": i, "_source": d} for i, d in self.data.items() if f(d)])
if query.fields:
return wrap({"hits": {"total": len(filtered), "hits": [{"_id": d._id, "fields": unwrap(jx.select([unwrap(d._source)], query.fields)[0])} for d in filtered]}})
else:
return wrap({"hits": {"total": len(filtered), "hits": filtered}})
开发者ID:klahnakoski,项目名称:MoTreeherder,代码行数:8,代码来源:elasticsearch.py
示例18: _select_a_field
def _select_a_field(field):
if isinstance(field, basestring):
return wrap({"name": field, "value": split_field(field)})
elif isinstance(wrap(field).value, basestring):
field = wrap(field)
return wrap({"name": field.name, "value": split_field(field.value)})
else:
return wrap({"name": field.name, "value": field.value})
开发者ID:klahnakoski,项目名称:MoDataSubmission,代码行数:8,代码来源:jx.py
示例19: run
def run(query, frum=None):
"""
THIS FUNCTION IS SIMPLY SWITCHING BASED ON THE query["from"] CONTAINER,
BUT IT IS ALSO PROCESSING A list CONTAINER; SEPARATE TO A ListContainer
"""
query = QueryOp.wrap(query, frum.schema)
frum = coalesce(frum, query["from"])
if isinstance(frum, Container):
return frum.query(query)
elif isinstance(frum, (list, set, GeneratorType)):
frum = wrap(list(frum))
elif isinstance(frum, Cube):
if is_aggs(query):
return cube_aggs(frum, query)
elif isinstance(frum, QueryOp):
frum = run(frum)
else:
Log.error("Do not know how to handle {{type}}", type=frum.__class__.__name__)
if is_aggs(query):
frum = list_aggs(frum, query)
else: # SETOP
# try:
# if query.filter != None or query.esfilter != None:
# Log.error("use 'where' clause")
# except AttributeError:
# pass
if query.where is not TRUE_FILTER:
frum = filter(frum, query.where)
if query.sort:
frum = sort(frum, query.sort, already_normalized=True)
if query.select:
frum = select(frum, query.select)
if query.window:
if isinstance(frum, Cube):
frum = list(frum.values())
for param in query.window:
window(frum, param)
# AT THIS POINT frum IS IN LIST FORMAT, NOW PACKAGE RESULT
if query.format == "cube":
frum = convert.list2cube(frum)
elif query.format == "table":
frum = convert.list2table(frum)
frum.meta.format = "table"
else:
frum = wrap({
"meta": {"format": "list"},
"data": frum
})
return frum
开发者ID:klahnakoski,项目名称:esReplicate,代码行数:58,代码来源:jx.py
示例20: iter
def iter(data, depth):
if depth == 0:
for v in data:
yield wrap(v)
return
for v in data.values():
for v1 in iter(v, depth - 1):
yield wrap(v1)
开发者ID:klahnakoski,项目名称:Activedata-ETL,代码行数:9,代码来源:index.py
注:本文中的pyLibrary.dot.wrap函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论