How to get the output of groupby as below in spark scala - scala

After running groupby i got the result as
+--------------------+-----+
| City|count|
+--------------------+-----+
| Tyler| 2|
| Fairbanks| 1|
| Springfield| 12|
| Charleston| 7|
| Corona| 2|
I want the same result as below
Tyler : 2
Fairbanks : 1
Springfield : 12
I have to do it in scala spark.. not pysaprk

This question is a bit unclear. Please add more data like how your are printing the first output (putting the code will help).
Rest, based on output I can think of you are just taking some values from RDD and printing on console with default println. If thats the case, try mapping the data based on your output requirement and then use .mkstring("\n") over it. So pseudo code will look like
collectedResult.map(x=>s"${x._1} : ${x._2}").mkString("\n")
Note: this is just an example may not run just like that in editor. Also if the size of result is too big, this approach is not at all recommended.

Related

Problem with Postgresql, LIKE gives double results

I am currently working with Postgresql and I am facing a problem.
I have two tables "question" and "question_detail" in which there are codes. In "question_detail" are the codes including subcode so e.g. TB01Q07, TB01Q07a, TB01Q08_SQ002. Now I wanted to use the command LIKE to see if the table "question" also contains these records. But in "question.code" there are only codes without the following underscore. This is a table that was given to me, I find this somehow very stupid.
The problem is that when I search with LIKE the value TB01Q07a is listed twice. This is also understandable to me, since searching for TB01Q07% also returns the value TB01Q07a.
Does anyone know of a way to search only for TB01Q07a without it resulting in TB01Q07% as TB01Q07a?
Command
SELECT qd.code, qd.label, q.type
FROM public.question q,
public.question_detail qd
where CASE
WHEN qd.code = q.code THEN qd.code = q.code
ELSE qd.code like CONCAT(q.code,'%')
END;
question
| code | type |
| ---------|-------- |
| TB01Q07 | comment |
| TB01Q07a | comment |
| TB01Q08 | option |
**question_detail**
```none
| code | label |
| -------------- | ------|
| TB01Q07 | AB01 |
| TB01Q07a | AB02 |
| TB01Q08_SQL002 | AB03 |
I ran the SQL and wanted the TB01Q07a value to appear only once and not be listed twice.
I think I have found a solution with distinct on.
SELECT distinct on (qd.code) q.id_question,qd.code, q.question, q.question_type
FROM public.question q, public.question_detail qd
where qd.code like CONCAT(q.code,'%');
like('TB01Q07%') matches both TB01Q07 and TB01Q07a, so you get two rows for TB01Q07 and one row for TB01Q07a.
You need to be more precise and include the underscore. Also make sure it's escaped, _ means any one character in a like.
There is no need for a case, use or. Avoid using multiple from statements, use an explicit join with an explicit on. This is clearer and gives you more control over the join.
select qd.*, q.*
from public.question q
join public.question_detail qd
on qd.code = q.code OR qd.code like q.code || '\_%'
Demonstration.
Note: this problem doesn't exist if you use foreign keys. Assign unique IDs to question and reference them in question_detail. This is faster, shields you from changes to the question code, and ensures the referred to question exists.

How do you disable orientdb console string truncating / shotening?

I'm playing around with OrientDB and would like to stop the console from truncating the strings:
+----+-------+---------+--------+------------------+------------------+----------------------------------------------------+
|# |#RID |#CLASS |version |last_updated |name |attributes |
+----+-------+---------+--------+------------------+------------------+----------------------------------------------------+
|0 |#59:229|docker |6.8.10 |2021-03-19 17:3...|datastax/dse-se...|{docker={imageName=datastax/dse-server, imageTag=...|
+----+-------+---------+--------+------------------+------------------+----------------------------------------------------+
I'd like to actually see the entire record, not just the truncated version of it. Is this possible?
You can always increase the size of the "width" property.
SET WIDTH = 1000
I've managed to find something close enough to what I was looking for.
If you use the #RID of the record you are interested in - you can actually do this:
load record 59:229
+----+------------+--------------------------------------------------+
|# |NAME |VALUE |
+----+------------+--------------------------------------------------+
|0 |version |#6.8.10 |
|1 |last_updated|2021-03-19 17:37:35 |
|2 |attributes |[{imageName=datastax/dse-server, imageTag=6.8.10}]|
|4 |name |datastax/dse-server |
|5 |version |6.8.10 |
+----+------------+--------------------------------------------------+
If that's still not enough - then you can use display record or even display raw record to get the most details.
I'd still prefer it if I could use the tabular view (i.e. SELECT FROM ..), but I couldn't find a way to do it. If anybody finds it - feel free to answer and I'll mark it as the accepted answer.

How to re-align column of text table in emacs?

When I insert a table using M-x table-insert
I get the following table:
+-----+-----+-----+
| | | |
+-----+-----+-----+
| | | |
+-----+-----+-----+
| | | |
+-----+-----+-----+
But When I add content the | become disaligned like this
+-----+-----+-----+
| content | | |
+-----+-----+-----+
| | | |
+-----+-----+-----+
| | | |
+-----+-----+-----+
How do you realign the column?
When I press enter it just creates that:
+-----+-----+-----+
| contecnt | | |
| | | |
+-----+-----+-----+
| | | |
+-----+-----+-----+
| | | |
+-----+-----+-----+
You enter the corresponding cell and start editing the text with C-c' it opens the edit mode and automatically wraps the text accordingly. Once done type C-c' again and you're back in the nicely formated table.
The table should expand as needed for words longer than the width of the column, and the entire column should widen when this happens. Multiple words will wrap appropriately when the width is reached if there is space to break the line. Remember to use tab to move from cell to cell in the table.
Column width can be changed manually with M-x table-widen-cell and M-x table-narrow-cell.
Sometimes Emacs gets confused for some reason, and something like what you describe happens. One way to fix it is to exit table mode with M-x table-unrecognize-table, manually edit the table, then do M-x table-recognize-table. It's not ideal, but sometimes is easiest.
Yes, org-mode table and table-mode table functionality are interfering with one another and preventing the table from realigning properly. I'm not sure how to fix that, but you mentioned in a comment that you are using table-mode specifically because you want multi-lined cells in the table.
I suggest that instead you use an org table (with M-x org-table-create) and then you can split long lines over multiple lines within the same cell by calling M-x org-table-wrap-region at the point where you want the split.
Just press TAB within the table and it will autoalign.

Formatting tables in Swift documentation comments

I have a section of code like this sitting above my computed property:
/**
Data Types Conversions:
-----------------------
+-----------------+-------------+
| kernel | Swift/Obj-c |
+=================+=============+
| sampler | CISampler |
| __table sampler | CISampler |
| __color | CIColor |
| float | NSNumber |
| vec2/3/4 | CIVector |
+-----------------+-------------+
*/
When it is rendered in the formatted comments pop-up I see garbled text.
Is there a way to represent this data in a table that actually renders when you option-click on the associated computed property?
I solved this problem with a code indent.
I don't know of any code markup for tabular formatting like that. I suggest you check Apple's site on their code documentation format:
https://developer.apple.com/library/content/documentation/Xcode/Reference/xcode_markup_formatting_ref/Throws.html#//apple_ref/doc/uid/TP40016497-CH26-SW1
You can also do this without indenting by using a "fenced" code block, surrounding your table (or code block) by triple backticks (```), the same way it works on stack overflow. But indenting may be cleaner and save vertical space.

Multiple SQLite Queries on iOS

I have more than 3 views. My database looks like this:
Category:
CatID | CatTitle
----------------
1 | XYZ
2 | Sample
Content:
ItemID | ItemCatID | ItemText | ItemText2 | ItemText3 | ItemText4
-----------------------------------------------------------------
1 | 1 | Test | Bla | Sample | MoreContent
2 | 1 | Test2 | BlaBla | Sample2 | Other Content
3 | 2 | Test3 | BlaBla2 | Sample3 | Other Content2
I want a view where first page category, second page list (ItemText), third page detail.
I'm not sure how to go about accomplishing that. If I use JOIN should I define "sqlite3_stmt *compiledStatement" in triple?
I think it can be done with 'For', "get parent,child" (like a cursor in java)?
Any advice welcome.
I'm not sure what you want.
Can you be more specific?
I can give you two tips though, first SQLite does not support stored procedures and has a very limited support for PL/SQL:http://www.sqlite.org/whentouse.html
if you REALLY MUST use it I suggest looking at this, I never tried it but it may work:
http://chriswolf.heroku.com/articles/2011/01/26/adding-stored-procedures-to-sqlite
Second, you usually wanna use a Wrapper around SQLite c functions so you worry about the SQL itself more and less about the c functions, examples:
Best Cocoa/Objective-C Wrapper Library for SQLite on iPhone
Hope this helps