text stringlengths 0 828 |
|---|
'REVOKE ALL ON ALL TABLES IN SCHEMA {0} FROM {1};' |
'REVOKE ALL ON ALL SEQUENCES IN SCHEMA {0} FROM {1};' |
'REVOKE ALL ON ALL FUNCTIONS IN SCHEMA {0} FROM {1};'.format(schema_name, roles))" |
3813,"def schema_exists(cls, cur, schema_name): |
"""""" |
Check if schema exists |
"""""" |
cur.execute(""SELECT EXISTS (SELECT schema_name FROM information_schema.schemata WHERE schema_name = '{0}');"" |
.format(schema_name)) |
return cur.fetchone()[0]" |
3814,"def pandas(self): |
""""""Return a Pandas dataframe."""""" |
if self._pandas is None: |
self._pandas = pd.DataFrame().from_records(self.list_of_dicts) |
return self._pandas" |
3815,"def translate(self, dialect): |
""""""Return a copy of this ResultSet in a different dialect."""""" |
new_resultset = copy(self) |
new_resultset.dialect = dialect |
for result in new_resultset: |
for dimensionvalue in result.dimensionvalues: |
dimensionvalue.value = dimensionvalue.translate(dialect) |
return new_resultset" |
3816,"def append(self, val): |
""""""Connect any new results to the resultset. |
This is where all the heavy lifting is done for creating results: |
- We add a datatype here, so that each result can handle |
validation etc independently. This is so that scraper authors |
don't need to worry about creating and passing around datatype objects. |
- As the scraper author yields result objects, we append them to |
a resultset. |
- This is also where we normalize dialects. |
"""""" |
val.resultset = self |
val.dataset = self.dataset |
# Check result dimensions against available dimensions for this dataset |
if val.dataset: |
dataset_dimensions = self.dataset.dimensions |
for k, v in val.raw_dimensions.items(): |
if k not in dataset_dimensions: |
d = Dimension(k) |
else: |
d = dataset_dimensions[k] |
# Normalize if we have a datatype and a foreign dialect |
normalized_value = unicode(v) |
if d.dialect and d.datatype: |
if d.dialect in d.datatype.dialects: |
for av in d.allowed_values: |
# Not all allowed_value have all dialects |
if unicode(v) in av.dialects.get(d.dialect, []): |
normalized_value = av.value |
# Use first match |
# We do not support multiple matches |
# This is by design. |
break |
# Create DimensionValue object |
if isinstance(v, DimensionValue): |
dim = v |
v.value = normalized_value |
else: |
if k in dataset_dimensions: |
dim = DimensionValue(normalized_value, d) |
else: |
dim = DimensionValue(normalized_value, Dimension()) |
val.dimensionvalues.append(dim) |
# Add last list of dimension values to the ResultSet |
# They will usually be the same for each result |
self.dimensionvalues = val.dimensionvalues |
super(ResultSet, self).append(val)" |
3817,"def tuple(self): |
"""""" Tuple conversion to (value, dimensions), e.g.: |
(123, {dimension_1: ""foo"", dimension_2: ""bar""}) |
"""""" |
return (self.value, {dv.id: dv.value for dv in self.dimensionvalues})" |
3818,"def allowed_values(self): |
""""""Return a list of allowed values."""""" |
if self._allowed_values is None: |
self._allowed_values = ValueList() |
for val in self.scraper._fetch_allowed_values(self): |
if isinstance(val, DimensionValue): |
self._allowed_values.append(val) |
else: |
self._allowed_values.append(DimensionValue(val, |
Dimension())) |
return self._allowed_values" |
3819,"def append(self, val): |
""""""Connect any new items to the scraper."""""" |
val.scraper = self.scraper |
val._collection_path = copy(self.collection._collection_path) |
val._collection_path.append(val) |
super(ItemList, self).append(val)" |
3820,"def _move_here(self): |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.