Let's say you have a table of properties in a Google Sheet...
Col A (Name)
Property 1
Property 2
Property 3
Property 4
Property 5
... and you want a formula-driven solution that pulls data on certain properties, specified by a comma-separated literal string like "Property 2,Property 5".
The query() function comes to mind, which uses mySQL syntax. I tried these WHERE queries:
SELECT A WHERE 'Property 2, Property 5' LIKE '%{$A}%' -- No error but returns empty set.
SELECT A WHERE INSTR('Property 2, Property 5', A) -- returned error: Unable to parse query string for function QUERY parameter 2: PARSE_ERROR: Encountered " 'INSTR'" at line 1, column 16. Was expecting one of: "("... "("...
Is there some other query to find the needle in the haystack, where the haystack is a literal string and the needle is a field in the query?
try:
=QUERY(A:A; "select A where A matches 'Property 2|Property 5'"; )
Related
I'm trying to get substring dynamically and group by it. So if my uri column contains records like: /uri1/uri2 and /somelongword/someotherlongword I would like to get everything up to second delimiter, namely up to second / and count it. I'm using this query but obviously it is cutting string statically (6 letters after the first one).
SELECT substr(uri, 1, 6) as URI,
COUNT(*) as COUNTER
FROM staging
GROUP BY substr(uri, 1, 6)
ORDER BY COUNTER DESC
How can I achieve that?
You can use combination of SUBSTRING() and POSITION()
schema:
CREATE TABLE Table1
(`uri` varchar(10))
;
INSERT INTO Table1
(`uri`)
VALUES
('some/text'),
('some/text1'),
('some/text2'),
('aa/bb'),
('aa/cc'),
('bb/cc')
;
query
SELECT
SUBSTRING(uri,1,POSITION('/' IN uri)-1),
COUNT(*)
FROM Table1
GROUP BY SUBSTRING(uri,1,POSITION('/' IN uri)-1);
http://sqlfiddle.com/#!9/293dd3/3/0
edit: here I found amazon athena documentation: https://docs.aws.amazon.com/athena/latest/ug/presto-functions.html and here is the string function documentation: https://prestodb.io/docs/0.217/functions/string.html
my answer above still stands, but you might need to change SUBSTRING to SUBSTR
edit 2: it seems there's a special function to achieve this in amazon athena called SPLIT_PART()
query:
SELECT SPLIT_PART(uri, '/', 1), COUNT(*) FROM tbl GROUP BY SPLIT_PART(uri, '/', 1)
from docs:
split_part(string, delimiter, index) → varchar
Splits string on delimiter and returns the field index. Field indexes start with 1. If the index is larger than than the number of fields, then null is returned.
I am trying to use Apache Calcite's SqlParser to get entity level lineage for my views written in Hive and Impala. However, the parser throws an exception for the following cases.
SELECT emp.1ab FROM emp -- Column name begins with numeric
org.apache.calcite.sql.parser.SqlParseException: Encountered ".1" at line 1, column 12.
Was expecting one of:
<EOF>
"AS" ...
SELECT PERIOD from emp -- column name is a key word (period)
Caused by: org.apache.calcite.sql.parser.impl.ParseException: Encountered "period from" at line 1, column 9.
Was expecting one of:
"ALL" ...
This is my SqlParser config.
SqlParser.Config config = SqlParser
.configBuilder()
.setConformance(SqlConformanceEnum.LENIENT)
.build();
Is there any other config setting available to customize the parser to suit my needs. All these queries are valid in Hive.
I need a full dql query to find all the attributes (single and Repeating) for the documents. I haven't tried any query.
You can select all attributes for object type using this query:
SELECT DISTINCT attr_name, attr_type, attr_repeating, attr_length FROM dm_type WHERE name = 'dm_document' ORDER BY attr_name
Where you replace dm_document by your target object type name and
attr_name contains attribute name
attr_type defines attribute type (0 - Boolean, 1 - Integer, 2 - String, 3 - ID, 4 - Time, 5 - Double)
attr_repeating indicates whether the attribute is repeating or not
attr_length defines size of String based attributes
If you want only attributes for that object type and not ones inherited from super type then you can select them by this query:
SELECT DISTINCT r_object_id, attr_name, attr_type, attr_repeating, attr_length, i_position, start_pos FROM dm_type WHERE name = 'dm_document' AND i_position < -start_pos ORDER BY attr_name ENABLE(ROW_BASED)
You could also use a "describe " to get information.
You should also investigate the views underneath if you're querying from non-dql application.
I am trying to run a SharePoint api query to match against a column with a specific value.
The column value contains a space which is resulting in the query not working as expected. Returning anything with 'value' in the column rather than just items where the column = 'value 2'.
My current url looks like where $listId is a list guid
https://mysite.sharepoint.com/_api/search/query?querytext='(customColumn:value 2)+AND+(ListID:$listId)'&selectproperties='Name,Title,Description,Author,LastModifiedTime,Path'
What is the syntax for
(customColumn:value 2)
That allows me to only return results where customColumn = "value 2"?
Try to encode the endpoint as
_api/search/query?querytext='customColumn:value%202'
My test Sample:
/_api/search/query?querytext='Title:Developer%20-%20Wiki1 Author:Lee'
I have a large table key(keyid,data) . In this table data consists of a text separated by /.
Eg x/y/z . I wish to extract the 2nd field (in the example y) for all the values stored in datails column in the table.
I tried using these
dblp1=# select regexp_split_to_array((select key from keytable),'/') as key_split;
ERROR: more than one row returned by a subquery used as an expression
dblp1=# SELECT split_part((select key from keytable), '/', 2);
ERROR: more than one row returned by a subquery used as an expression
Both work on single string .
Pretty close. You need the function to be wrapped right around the column name, like so:
select split_part(key, '/', 2) from keytable;