Is there any way select by ordinal number in Presto? - presto

From the doc, we can group by ordinal in Presto:
SELECT count(*), nationkey FROM customer GROUP BY 2;
SELECT count(*), nationkey FROM customer GROUP BY nationkey;
My question, is there any way to select by ordinal number? I just want something like:
SELECT customer.1, customer.2 FROM customer;

It is not currently possible.
As a workaround, you can generate such a query using information_schema (it's not documented today, see https://github.com/trinodb/trino/issues/5345). format() function can be useful. However you accomplish this, you need to re-submit generated SQL yourself.

Related

Cassandra: filtering based one specific value in a set

I have a data table in Cassandra and one of the columns is:
customer_favourites, with each value being of type set and it has the details of each customer's favourite foods. For example one customer could have {'Mexican', 'Italian', 'Indian'} and another customer could have {'Mexican', 'French'} and another could have {'Mexican'}.
I have the following code:
SELECT customer_id, customer_fname, customer_lname FROM customers WHERE customer_favourites CONTAINS ‘Mexican’ ALLOW FILTERING;
I want it to filter on those customers whose favourite food is ONLY Mexican, but right now it's returning the details of every customer who has Mexican as one of their favourite foods. How do I filter my query to return customer who like ONLY Mexican food?
Naive approach: You need to use customer_favourites = {'Mexican'}...
Better approach - create secondary index on the corresponding field, using the FULL keyword, and then use customer_favourites = {'Mexican'}.
Best approach - create a separate table with customer_favourites as partition key, and search users in it (column should be frozen). One of the problems with this approach would be the data skew, as number of favorite foods is relatively small, and quite imbalanced.
Alternative approach - reconsider the use of the Cassandra, if you need to search by non-partition key very often.

how to provide result of one query to another in azure document DB

if i have to pass a list of numbers got from one select statement to another select statement both working on the same collection, how will I be able to perform that ?
Query:
SELECT VALUE student.studentId
FROM student
where student.acctType="student"
This gives me a result:
["1","2","3","4"]
The query, if I had those values
SELECT student.firstName,
student.lastName
from student
where student.acctType="student" AND
student.studentId IN ("1","2","3","4")
This is what I tried but did not work :
SELECT student.firstName,
student.lastName
from student
where student.acctType="student" AND
student.studentId IN ( SELECT VALUE student1.studentId
FROM student1
where student1.acctType="student")
DocumentDB has an SQL-familiar query syntax but it's still a NoSQL database. As such, it has no support for inter-document joins and no support for sub-queries. That's the bad news.
The good news is that DocumentDB allows you to write stored procedures (sprocs) to accomplish everything you could with full SQL and much much more. You could write a sproc that did the query that returned the list of numbers, then use that list of numbers to compose another query to get your the data you need.
That said, for the simple use case you describe, you could accomplish the same thing client-side with two round trips.

ms sql search by nvarchar field

I am using MS SQl 2012 and have simple table
id (int) - primary key
fullname (nvarchar(500)
age (int)
…
In table over 15 millions records and I need make simple search like
select * from Customers where full name like '%sometext%'
Details:
1. It can have few words
2. There are used many languages
3. that fullname doesn't have any indexes yet
What the best way make search like that? Which indexes I should add? Can I use full text search if there are not only english words?
Sargable The above query does not meet the requirements therefore no index on your full name column is going to help. You will need to restructure your data or filter on something sargable first (age = 30) and then scan full name.
The other option is to pull in a text searching technology as #afrancis indicated.

What query to issue to extract only column names(no values)?

RangeSliceQuery has a convenient method to extract only the keys - setReturnKeysOnly() but I couldn't find something similar in SliceQuery (like setReturnColumnNamesOnly()).
Is this functionality provided somewhere in Hector API?
If you want get only column names belonging to a particular column family, i can show you a way how you can achieve it using cql
select * from system.schema_columns WHERE keyspace_name='#KS' AND columnfamily_name='#CF' allow filtering;
Now i don't think it will be great technical hurdle to achieve the same thing using your hector api.
Cheers

Order SharePoint search results by more columns

I'm using a FullTextSqlQuery in SharePoint 2007 (MOSS) and need to order the results by two columns:
SELECT WorkId FROM SCOPE() ORDER BY Author ASC, Rank DESC
However it seems that only the first column from ORDER BY is taken into account when returning results. In this case the results are ordered correctly by Author, but not by Rank. If I change the order the results will be ordered by Rank, but not by Author.
I had to resort to my own sorting of the results, which I don't like very much. Has anybody a solution to this?
Edit: Unfortunately it also doesn't accept expressions in the ORDER BY clause (SharePoint throws an exception). My guess is that even if the query looks like legitimate SQL it is parsed somehow before being served to the SQL server.
I tried to catch the query with SQL Profiler, but to no avail.
Edit 2: In the end I used ordering by a single column (Author in my case, since it's the most important) and did the second ordering in code on the TOP N of the results. Works good enough for the project, but leaves a bad feeling of kludgy code.
Microsoft finally posted a knowledge base article about this issue.
"When using RANK in the ORDER BY clause of a SharePoint Search query, no other properties should be used"
http://support.microsoft.com/kb/970830
Symptom: When using RANK in the ORDER BY clause of a SharePoint Search query only the first ORDER BY column is used in the results.
Cause: RANK is a special property that is ranked in the full text index and hence cannot be used with other managed properties.
Resolution: Do not use multiple properties in conjunction with the RANK property.
Rank is a special column in MOSS FullTextSqlQuery that give a numeric value to the rank of each result. That value will be different for each query, and is relative to the other results for that particular query. Because of this rank should have a unique value for each result, and sorting by rank then author would be the same as just sorting by rank. I would try sorting on another column instead of rank to see if results come back as you expect, if so your trouble could be related to the way MOSS is ranking the results, which will vary for each unique query.
Also you are right, the query looks like SQL, but it is not the query actually passed to the SQL server, it is special Microsoft Enterprise Search SQL Query syntax.
I, too, am experiencing the same problem with FullTextSqlQuery and MOSS 2007 where only the first column in a multi-column "ORDER BY" is respected.
I entered this topic in the MSDN Forums for SharePoint Search, but have not received any replies:
http://social.msdn.microsoft.com/Forums/en-US/sharepointsearch/thread/489b4f29-4155-4c3b-b493-b2fad687ee56
I have no experience in SharePoint, but if it is the case where only one ORDER BY clause is being honored I would change it to an expression rather than a column. Assuming "Rank" is a numeric column with a maximum value of 10 the following may work:
SELECT WorkId FROM SCOPE() ORDER BY AUTHOR + (10 - Rank) ASC

Resources