Retrieving number of distinct values in Parse? - parse-platform

Is there any Parse equivalent to the SQL statement, SELECT DISTINCT?
I have the tables: User, Group, Tag, and Post. Each user has posts and can create tags and groups. The Tag table contains the fields:
"name" String
"post" Pointer<Post>
"creator" Pointer<_User>
I am trying to make a cloud function to return the most popular tags to my Android app for an AutoCompleteTextView. I was thinking that I should just do something like a SELECT DISTINCT name query in Parse and order by descending, but you can't do that in Parse. Is there any workaround for this?
I saw that this post did not get an answer and that this post says to work out distinct values client-side.
Thanks

It's not implemented yet, check this answer on Parse.com, which you've mentioned it too:
https://parse.com/questions/retrieving-unique-values
The answer in following post is actually means: read all rows, select unique ones :)

Related

How can I order by date in jpa query

Please I want to write a jpa query for this table: payment_transaction
I am making a http request with a list of taxpayer references (since it is unique). I want to get all last payment_transaction record for all taxpayers with taxpayer_reference in my http request list of taxpayer_reference using a single query. I know that: paymentTransactionRepository.findAllByTaxPayerReferenceIn(List<String> taxPayerReferences) will give me all the payment transaction records that has a taxPayerReference in the parameter I will pass but I want to get the last payment made by each taxPayerReference. I guess I should order by paymentDate in descending order and get the first record for each taxPayerReference as wellPS: In single jpa queryI don't know if that's possible. Please help me write the query. Thanks
You can try like below.
findByAgeOrderByLastnameDesc(Long age)
Which will be generated as below when you run
where x.age = ?1 order by x.lastname desc
For your particular example,
paymentTransactionRepository.findAllByTaxPayerReferenceInOrderByPaymentDateDesc(List<String> taxPayerReferences)
More examples on this available here

How to allow user to add information for every fields in forms

i have a strange user request: they want to be able to say for every fields in every forms from where they get information used to compile it.
value must be selected from a list
essentially iam looking a way to avoid to double the fields.
one way can be add a M:M table where link field-name and information-source
but using this for retrive from real data table only fields derived from an info-source can be really bad
EDIT
to be more clear the solution i want to avoid is to have a data table like this:
fieldname1
fieldname1Origin
fieldname2
fieldname2Origin
fieldname3
fieldname3Origin
...
but i do the link table in this way:
FieldName
OriginId
i have to map oll field names and to search in it with string name when i need to query data table i have to do something like this
select
case when (exists select 1 from LinkTable where FieldName='fieldname1' AND
OriginId=SelectedID) then fieldname1
else NULL
end
for every fields
What about mixing several controls, such as a combobox with all lines, that would trigger the display of all columns of that line.
Something like that (I am currenlty working on that project):

Passing more than 3 items in a reports column link

I have a report that is listing students and I want a column to edit a student. I've done so by following this answer:
How do you add an edit button to each row in a report in Oracle APEX?
However, I can only seem to pass 3 items and there's no option to add more. I took a screenshot to explain more:
I need to pass 8 values, how can I do that?
Thanks!
Normally, for this you would only pass the Primary Key columns (here looks like #RECORD_NUMBER# only). The page that you send the person to would then load the form based on the primary key lookup only. If multiple users were using this application, you would want the edit form to always retrieve the current values of the database, not what happened to be on the screen when a particular person ran a certain report.
Change the Target type to URL.
Apex will format what to already have into a URL text field which magically appears between Tem3 and Page Checksum.
All you need to do is to add your new items and values in the appropriate places in the URL.
I found a workaround, at least it was useful to my scenario.
I have an IR page, query returns 4 columns, lets say: ID, DESCRIPTION, SOME_NUMBER,SOME_NUMBER2.
ID NUMBER(9), DESCRIPTION VARCHAR2(30), SOME_NUMBER NUMBER(1), SOME_NUMBER2 NUMBER(3).
What I did was, to setup items this way:
P11_ITEM1-->#ID#
P11_ITEM2-->#DESCRIPTION#
P11_ITEM3-->#SOME_NUMBER##SOME_NUMBER2#
Previous data have been sent to page 11.
In page 11, all items are display only items.
And P11_ITEM3 actually received two concatenated values.
For example, the calling page has columns SOME_NUMER=4 and SOME_NUMBER2=150
so, in pag1 11, P11_ITEM3 shows 4150
In page 11 I created a Before Footer process (pl/sql expression)
to set up new items, for example P11_N1 as source SUBSTR(P11_ITEM3,1,1)
and item P11_N2 as source SUBSTR(P11_ITEM3,2,3)
So, I had those items with corresponding values from the calling IR page.
The reason I did not pass the primary key only for new lookup access, is because i do not want to stress database performing new queries since all data are already loaded into page items. I've been an oracle DBA for twenty years and I know there is no need to re execute queries if you already have the information somewhere else.
These workarounds are not very useful for a product that bills itself as a RAD tool.
Just include a single quoted word in the select statement (Select col1, 'Randomword', col2 from table 1;)
Then define that column as a link and bingo! More items than 3 to select.

iReports Grouping Bug - Multiple Occurrences?

I'm am getting irritated with iReports. Problem is that I have a data set returning data for multiple customers and I want to use the "Group Expression" against the customer ID and have the report lay out the Detail Tabs per customer.
I'm finding that, seeming randomly, where there is more that one data row for a customer iReports will generate two or more groupings (Sometimes it does what I expect and group all the customer data together), the field IDing the customer is the same and doesn't change.
Has anyone seen this before? To be honest I can't believe it is actually a bug, but something I've missed. Just much searching as yet to find a suitable result.
I think this is a data sorting problem.
The quote from iReport Ultimate Guide:
JasperReports groups records by evaluating the group expression. Every
time the expression's value changes, a new group instance is created.
The engine does not perform any record sorting (if not explicitly
requested), so when we define groups we should always take care of the
records sorting. That is, if we want to group a set of addresses by
country, the records we select for the report should already by
ordered by country. It is simple to sort data when using an SQL query
by using the ORDER BY clause. When this is not possible (that is, when
obtaining the records from an XML document), we can request that
JasperReports sort the data for us. This can be done using the sort
options available in the query window
You can sort data in these ways:
in case using of Database jdbc connection datasource type you can add ORDER BY customerId clause to the report's query, where customerId - column name of field with customer id
in case using of File csv connection or something like this you can organize data sorting by adding sortField property for field to the report's template (jrxml file):
<jasperReport ...>
...
<field name="customerId" class="java.lang.String"/>
<sortField name="customerId"/>
SQL Statement has ORDER BY?
iReport group is grouped by customer_id?

Seam EntityQuery Many-to-Many Joins, Distinct, and Oracle

I'm a Seam newbie in an already established project, so a lot of code I use is borrowed and I'm not always fully sure how things work. My problem is that I am using a query object extended from EntityQuery to back a list page with search and sort capabilities that needs to search across a many-to-many relationship and a separate many-to-one relationship which must also be used to sort. Because the many-to-many relationship has to be joined in to allow for the search capability, the query returns duplicate records for each assignment. That's not a big deal because I just added "distinct" to the ejbql and that worked fine. However, when I try to order by the other many-to-one relationship, Oracle throws an error. It appears that Oracle will not accept an order by column that is not in the select clause when using the distinct keyword http://ora-01791.ora-code.com/, and http://oraclequirks.blogspot.com/2009/04/ora-01791-not-selected-expression.html.
Here are the relationships as they are defined in the entities: [Subject m:m JobFunction] (obviously through an assignment table [Subject o:m Subject_JobFunction m:o JobFunction]), and [Subject m:o Type]. Because I need to search Subject by JobFunction, it is joined in in the ejbql which requires the distinct keyword to only return distinct Subjects to the list page. When I try to order by the Type.name (through the many-to-one relationship), the resulting query makes Oracle angry and throws the "ORA-01791: not a SELECTed expression" error. SubjectQuery code:
#Override
public String getEjbql() {
return "select subject from Subject subject left outer join subject.jobFunctions as jobFunction";
}
#Override
#SuppressWarnings("rawtypes")
public List<ValueExpression> getRestrictions() {
ValueExpression[] RESTRICTIONS = {
createValueExpression("lower(subject.name) like #{subjectQuery.prepRestriction(subjectQuery.subject.name)}"),
createValueExpression("subject.active = #{subjectQuery.active}"),
createValueExpression("subject.type.name = #{subjectQuery.typeName}"),
createValueExpression("jobFunction.name = #{subjectQuery.jobFunctionName}")
};
return Arrays.asList(RESTRICTIONS);
}
When I set the query order when a user sorts by the Type name through the front end:
"#{subjectQuery.order=='UPPER(subject.type.name) asc'}"
I get the Oracle error. If I take the distinct out of the ejbql, the sort works fine, but I get duplicate Subject records. When I add the distinct keyword the list works fine without duplicate records, but the sort throws an error. Does anyone have any suggestions about how I can restructure the ejbql to return distinct records without the distinct keyword to make the sort happy, or how to do the sort without making Oracle angry that the sort column referenced in the query is not in the select clause? I have read several places that my answer might be in the the Hibernate Criteria API, but I have no idea how to leverage it in the context of an extended EntityQuery class with what I am trying to accomplish. Please Help!
If you are adding a DISTINCT, then something is broken.
"Because the many-to-many relationship has to be joined in to allow for the search capability, the query returns duplicate records for each assignment. "
Consider the case that a person can work on many projects and a project can have many persons. There is a uniqueness of a 'person/project'. If you want a list of people that work in either project A or B (or both) then you may get
FRED/PROJ_A
BILL/PROJ_A
FRED/PROJ_B
TOM/PROJ_B
BILL/PROJ_C
If you only show the names (not the projects), you can still order by project, but you will see
FRED
BILL
FRED
TOM
BILL
If you do a DISTINCT, you can no longer order by project, because you don't know whether the FRED is the one from PROJ_A or PROJ_B or whether BILL comes before TOM (based on PROJ_A) or after TOM (based on PROJ_C).
So remove the DISTINCT and always show the column on which you are ordering (because then you'll see why the duplicates aren't actually duplicates).
I'm not sure how the generated query(ies) is(are) different, but I found an answer. I wasn't aware of the fetch command for hibernate, which fixes the need for the distinct keyword (again, not sure exactly how, maybe by subquerying?). After changing the ejbql to:
#Override
public String getEjbql() {
return "select subject from Subject subject left join fetch subject.jobFunctions jobFunction";
}
the distinct is no longer needed and therefore, Oracle does not complain about the order by column not being in the select clause. The list works as expected and the sort column works! Yay!
Predictably, I found the answer here on stackoverflow. The question was not exactly the same, but the hql syntax worked for me: HQL order by within a collection

Resources