Sqlite3 shell output: word wrap single columns - bash

I am interacting with a sqlite3 database on linux with bash scripts. It is a small tool I use for myself. I am displaying the data in the terminal. Some of the columns contain a lot of text, too much to show in a single line. Is there a possibility to word wrap the output of the select-query? The output I am looking for should look something like this:
rowid | column1 | column2 | column3
------------------------------------------------
1 | value 11 | value 21 | value 31
------------------------------------------------
2 | value 12 | This is a | value 32
| | very long |
| | text |
------------------------------------------------
3 | value 13 | value 23 | value 33
------------------------------------------------
4 | value 14 | value 24 | value 34
Is there a possibility to do this? I was not able to find a solution to this problem. Thanks in advance and BR!

Related

How can i merge multiple columns from two different files in talend

Lets say i have multiple columns coming from two different files like that :
USERNAME | AGE | GENDER | CHILDREN
Joe | 23 | male | 2
Annie | 45 | female | 5
| | |
And another one like this :
USERNAME | AGE |
Jonathan | 33 |
Mike | 41 |
And i want to merge the data of the columns that have the same name into one like this while keeping the data of the columns that are unique at each field:
USERNAME | AGE | GENDER | CHILDREN
Joe | 23 | male | 2
Annie | 45 | female | 5
Jonathan | 33 | |
Mike | 41 | |
Sorry if the answer is obvious, im new to talend, thanks.
What tool is available toy you?
The Append function in SAS for example can do this for you.
You can use the append approach in Python, R or other language you intend using.
For Talen:
Copy the complete subjob1 – copy me sub job and paste it to create a second sub job.
Link the two sub jobs using an onSubjobOK link.
Open tFixedFlowInput, and change Records from first subjob to Records from second subjob.
Open tFileOutputDelimited on the new sub job, and tick Append, as shown in the following screenshot:
use a tUnite component to accomplish that
here is the link of the documentation : https://help.talend.com/r/fr-FR/8.0/orchestration/tunite
your flow would be
tFileInput1(excel or csv ) ----------------------------------------------
|
| ->tUnite -> tLogRow
tFileInput2(excel or csv )->tMap (add to empty fields GENDER & Children )|

Efficient way to join by levenshtein in Hive or Impala

I have two tables one includes about 17K (NLIST) records while the other 57K (FNAMES).
I would like to join the both by comparing the records using levenshtein formula.
Here is the example for the content of tables:
Table NLIST:
+------+-------------+
| ID | S_NAME |
+------+-------------+
| 1 | Avi |
| 2 | Moshe |
| 3 | David |
....
Table FNAMES:
+------+-------------+
| ID | NICKNAMES |
+------+-------------+
| 1 | Avile |
| 2 | Dudi |
| 3 | Moshiko |
| 4 | Avi |
| 5 | DAVE |
....
The above tables are just examples. In the real case the names column can include more than one word.
The required result should be:
+------+-------------+--------+
| ID | NICKNAMES | S_NAME |
+------+-------------+--------+
| 1 | Avile | Avi |
| 2 | Dudi | David |
| 3 | Moshiko | Moshe |
| 4 | Avi | Avi |
| 5 | DAVE | David |
...
Here is the code I use:
select FNAMES.NICKNAMES, NLIST.S_NAME
from NICKNAMES
LEFT OUTER JOIN NLIST
ON(true)
WHERE levenshtein (FNAMES.NICKNAMES, NLIST.S_NAME) <=4
The above code runs for a very long time and I stopped its running.
How can I make it run in a reasonable time?
In addition, I think the levenshtein distance depends on the length of the words. How can I find the optimal value for the distance (in this case I chose 4 arbitrarily)?
Hive Table performance is depends upon various point .
Query enginee
File format
use VECTORIZATION set hive.vectorized.execution.enabled = true;set hive.vectorized.execution.reduce.enabled = true;
If you have good server you can try with Impala and definitely it is faster than Hive.
You can do the fine tuning of impala which will give you an edge to execute this query faster .Tuning Impala for Performance

Get 1 value of each date SSRS

Ussing SSRS, I have data with duplicate values in Field1. I need to get only 1 value of each month.
Field1 | Date |
----------------------------------
30 | 01.01.1990 |
30 | 01.01.1990 |
30 | 01.01.1990 |
50 | 02.01.1990 |
50 | 02.01.1990 |
50 | 02.01.1990 |
50 | 02.01.1990 |
40 | 03.01.1990 |
40 | 03.01.1990 |
40 | 03.01.1990 |
It should be ssrs expression with average value of each month or mb there are other solutions to get requested data by ssrs expression. Requested data in table:
30 | 01.01.1990 |
50 | 02.01.1990 |
40 | 03.01.1990 |
Hope for help.
There is no SumDistinct function in SSRS, and it is real lack of it (CountDistinct exist although). So you obviously can't achieve what you want easy way. You have two options:
Implement a new stored procedure with select distinct, returning reduced set of fields to avoid repeated data that you need. You then need to use this stored procedure to build new dataset and use in your table. But this way obviously may be not applicable in your case.
The other option is to implement your own function, which will save state of aggregation and perform distinct sum. Take a look at this page, it contains examples of code that you need.

Select only the rows which timestamp correspond to the current month

I am starting to try some experiments using Google SpreadSheets as a DB and for that I am collecting data from different sources and inserting them via spreadsheets API into a sheet.
Each row has a value (Column B) and a timestamp (Column A).
+---------------------+------+
| ColA | ColB |
+---------------------+------+
| 13/10/2012 00:19:01 | 42 |
| 19/10/2012 00:29:01 | 100 |
| 21/10/2012 00:39:01 | 23 |
| 22/10/2012 00:29:01 | 1 |
| 23/10/2012 00:19:01 | 24 |
| 24/10/2012 00:19:01 | 4 |
| 31/10/2012 00:19:01 | 2 |
+---------------------+------+
What I am trying to do is to programmatically add the sum of all rows in Column B where Column A is equal to the current month into a different cell.
Is there any function that I can use for that? Or anyone can point me to the right direction on how can I create a custom function which might do something like this? I know how to do this using MySQL but I couldn't find anything for Google SpreadSheets
Thanks in advance for any tip in the right direction.
Would native spreadsheet functions do?
=ArrayFormula(SUMIF(TEXT(A:A;"MM/yyyy");TEXT(GoogleClock();"MM/yyyy");B:B))

multiline text in varchar2 field

I have a multiline date, and I'd like to insert it in a table. Then of course, I'd like to retrieve it while preserving the places of cartridge returns.
For example. I have data like this in text file
-------------------------------
| ID | text |
| | |
| 01 | This is headline. |
| 02 | This is all the text.|
| | ¤ |
| | Of great story once |
| 03 | Great weather |
-------------------------------
The ¤ is the indicator of cartridge return. When I try to run the query then data comes like this:
-------------------------------
| ID | text |
| | |
| 01 | This is headline. |
| 02 | This is all the text.|
| 03 | Great weather |
-------------------------------
What I'd like to have in table: (I have no idea how to show cartridge return in the example below)
-----------------------------------------------------
| ID | text |
| | |
| 01 | This is headline. |
| 02 | This is all the text. Of great story once |
| 03 | Great weather |
-----------------------------------------------------
Which is of course, wrong as the data for ID 02 wasn't imported completely.
Here is my script:
LOAD DATA
INFILE "file.txt" BADFILE "file.bad" DISCARDFILE "file.dsc"
APPEND
INTO TABLE text_table
FIELDS TERMINATED BY X'7C' TRAILING NULLCOLS
(
employee_id,
exp_pro CHAR(4000)
)
Any ideas?
First make sure the issue isn't with how you're viewing the data (or the IDE used). Sometimes viewers will simply stop at a linefeed (or carriage return, or some binary char).
Try dumping a hex representation of some data first. for example:
with txt as (
select 'This is line 1.' || chr(13) || chr(10) || 'Line 2.' as lines
from dual
)
select dump(txt.lines, 16) from txt;
You should be able to see the 0d0a (crlf) chars, or whatever other "non-printable" chars exists, if any.

Resources