Presto API to get active workers - api

I would like to use Presto API to get number of active workers, similar to the info available in PrestoUI.
I want to use the an API similar to (who don't contain this info):
https://presto/v1/status
https://presto/v1/jmx

AFAIK in latest Trino (formerly Presto SQL) versions the workers cannot be introspected from outside of the cluster, but you can get the listing with SQL:
presto> SELECT * FROM system.runtime.nodes;
node_id | http_uri | node_version | coordinator | state
---------------+------------------------+------------------+-------------+--------
presto-worker | http://172.20.0.3:8081 | 347-137-g4945abe | false | active
presto-master | http://172.20.0.4:8080 | 347-137-g4945abe | true | active
(2 rows)

Related

Longest Common Prefix Per Aggregate Using Apache Spark SQL

I am using apache spark to find the longest common prefix per session
Given the following example:
session | prefix
_____________________
1 | keys
1 | key chain
1 | keysmith
2 | tim
2 | timmy
2 | tim hortons
I would like to format this into the following output:
session | prefix
_____________________
1 | key
2 | tim
I saw an example which checks a column in one row against all others but I have trouble wrapping my head around how to do this for aggregate rows.
Any help is appreciated!
try like below
select session,min(length(prefix)) from table_name
group by session

CockroachDB: Simple SQL queries do not respond

I have setup CockroachDB according to the instructions at https://www.cockroachlabs.com/docs/stable/deploy-cockroachdb-on-premises-insecure.html. However, SQL queries take too long time and do not respond.
The procedure of setupping cluster is as follows. I used three machines running Ubuntu 19.10.
At node1
cockroach start --insecure --advertise-addr=${NODE1} --join=${NODE1},${NODE2},${NODE3} --cache=.25 --max-sql-memory=.25 --background
At node2
cockroach start --insecure --advertise-addr=${NODE2} --join=${NODE1},${NODE2},${NODE3} --cache=.25 --max-sql-memory=.25 --background
At node3
cockroach start --insecure --advertise-addr=${NODE3} --join=${NODE1},${NODE2},${NODE3} --cache=.25 --max-sql-memory=.25 --background
Here, ${NODEi} stands for the address of each node.
Then, I initialized the cluster.
cockroach init --insecure --host=${NODE1}
After that, I went into SQL shell and typed a query.
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v20.1.1 (x86_64-unknown-linux-gnu, built 2020/05/19 14:46:06, go1.13.9) (same version as client)
# Cluster ID: 77cf3b29-f895-45ab-9592-7956a3effdb7
#
# Enter \? for a brief introduction.
#
root#192.168.10.131:26257/defaultdb> CREATE DATABASE bank;
The command CREATE DATABASE bank took more than one minute and seemed not to work. But when I try again later, the same command finished within a second.
The status of cluster is as follows:
id | address | sql_address | build | started_at | updated_at | locality | is_available | is_live
-----+----------------------+----------------------+---------+----------------------------------+----------------------------------+----------+--------------+----------
1 | 192.168.10.131:26257 | 192.168.10.131:26257 | v20.1.1 | 2020-05-28 05:00:17.725807+00:00 | 2020-05-28 05:26:01.338089+00:00 | | true | true
2 | 192.168.10.132:26257 | 192.168.10.132:26257 | v20.1.1 | 2020-05-28 05:00:18.574806+00:00 | 2020-05-28 05:26:02.121931+00:00 | | true | true
3 | 192.168.10.133:26257 | 192.168.10.133:26257 | v20.1.1 | 2020-05-28 05:00:18.729008+00:00 | 2020-05-28 05:26:02.253278+00:00 | | true | true
(3 rows)
Do you have any ideas to solve this problem?
This doesn't look expected, perhaps it's related to the network topology of your cluster or the clusters resources at the time of the statement.
If this is still an issue there are two things we could try:
a) Upgrading to the latest stable version of 20.2 which introduces a ton of stability and performance upgrades.
b) Collect a debug.zip and you could submit a ticket to www.support.cockroachlabs.com for the technical support team to check out.
I recommend upgrading to the latest stable version of v20.1 or v20.2 and giving that a shot though!

ID Extracted from string not useable for connecting to bound form - "expression ... too complex"

I have a linked table to a Outlook Mailitem folder in my Access Database. This is handy in that it keeps itself constantly updated, but I can't add an extra field to relate these records to a parent table.
My workaround was to put an automatically generated/added ID String into the Subject so I could work from there. In order to make my form work the way I need it to, I'm trying to create a query that takes the fields I need from the linked table and adds a calculated field with the extracted ID so it can be referenced for relating records in the form.
The query works fine (I get all the records and their IDs extracted) but when I try to filter records from this query by the calculated field I get:
This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.
I tried separating the calculated field out into three fields so it's easier to read, hoping that would make it easier to evaluate for Access, but I still get the same error. My base query is currently:
SELECT InStr(Subject,"Support Project #CS")+19 AS StartID,
InStr(StartID,Subject," ") AS EndID,
Int(Mid(Subject,StartID,EndID-StartID)) AS ID,
ProjectEmails.Subject,
ProjectEmails.[From],
ProjectEmails.To,
ProjectEmails.Received,
ProjectEmails.Contents
FROM ProjectEmails
WHERE (((ProjectEmails.[Subject]) Like "*Support Project [#]CS*"));
I've tried to bind a subform to this query on qryProjectEmailWithID.ID = SupportProject.ID where the main form is bound to SupportProject, and I get the above error. I tried building a query that selects all records from that query where the ID = a given parameter and I still get the same error.
The working query that adds Support Project IDs would look like:
+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+
| ID | Subject | To | From | Received | Contents |
+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+
| 1 | RE: Support Project #CS1 ID Extra... | questions#so.com | Isaac.Reefman#so.com | 2019-03-11 | Trying to work out how to add... |
| 1 | RE: Support Project #CS1 ID Extra... | isaac.reefman#so.com | questions#so.com | 2019-03-11 | Thanks for your question. The... |
| 1 | RE: Support Project #CS1 ID Extra... | isaac.reefman#so.com | questions#so.com | 2019-03-11 | You should use a different me... |
| 2 | RE: Support Project #CS2 IT issue... | support#domain.com | someone#company.com | 2019-02-21 | I really need some help with ... |
| 2 | RE: Support Project #CS2 IT issue... | someone#company.com | support#domain.com | 2019-02-21 | Thanks for your question. The... |
| 2 | RE: Support Project #CS2 IT issue... | someone#company.com | support#domain.com | 2019-02-21 | Have you tried turning it off... |
| 3 | RE: Support Project #CS3 email br... | support#domain.com | someone#company.com | 2019-02-12 | my email server is malfunccti... |
| 3 | RE: Support Project #CS3 email br... | someone#company.com | support#domain.com | 2019-02-12 | Thanks for your question. The... |
| 3 | RE: Support Project #CS3 email br... | someone#company.com | support#domain.com | 2019-02-13 | I've just re-started the nece... |
+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+
The view in question would populate a datasheet that looks the same with just the items whos ID matches the ID of the current SupportProject record, updating when a new record is selected. A separate text box should show the full content of whichever record is selected in that grid, like this:
Have you tried turning it off and on again?
From: support#domain.com
On: 21/02/2019
Thanks for your question. The matter has been assigned to Support Project #CS2, and a support staff member will be in touch shortly to help you out. As it is considered of medium priority, you should expect daily updates.
Thanks,
Support
From: someone#company
On: 21/02/2019
I really need some help with my computer. It seems really slow and I can't do my work efficiently.
Neither of these things happens as when I try to use the calculated number to relate to the PK of the SupportProject table...
I don't know if this is a part of the problem, but whether I use Int(Mid(Subject... or Val(Mid(Subject... I still apparently get a Double, where the ID field (as an autoincrement ID) is a Long. I can't work out how to force it to return a Long, so I can't test whether that's the problem.
So that is output resulting from posted SQL? I really wanted raw data but close enough. If requirement is to extract number after ...CS, calculate in query and save query:
Val(Mid([Subject],InStr([Subject],"CS")+2))
Then build another query to join first query to table.
SELECT qryProjectEmailWithID.*, SupportProject.tst
FROM qryProjectEmailWithID
INNER JOIN SupportProject ON qryProjectEmailWithID.ID = SupportProject.ID;
Filter criteria can be applied to either ID field.
A subform can display the related child records synchronized with SupportProject records on main form.
I tested the ID calc with your data and then with a link to my Inbox. No issue with query join.

Dynamic creation of Table type

I have a column table with a single column.
I would like to create a table type with all the elements in the column of the above mentioned table as column names with fixed datatype and size and use it in a function.
similarly like below:
Dynamic creation of table in tsql
Any suggestions would be appreciated.
EDIT:
To finish a product, a machine has to perform different Jobs on the material with different tools.
I have a list of Jobs a machine can perform and a list of Tools. a specific tool for a specific Job.
Each job needs a specific tool and number of hours (to change the tool once it reached its change time). A Job can be performed many times on a product. (in this case if a Job is performed for 1 hour = tool has been used for 1 hour)
For each product, a set of tools will be at work in a sequence. so I Need a report for each product, number of hours the tool has worked.
EDIT 2:
Product table
---------+-----+
ProductID|Jobs |
---------+-----+
1 | job1 |
1 | job2 |
1 | job3 |
1 | . |
1 | . |
1 |100th |
2 | job1 |
2 | . |
2 | . |
2 |200th |
Jobs table
-------+-------+-------
Jobs | tool | time
-------+-------+-------
job1 |tool 10| 2
job1 |tool 09| 1
job2 |tool 11| 4
job3 |tool 17| 0.5
required report (this table does not physically exist)
----------+------+------+------+------+------+-----
productID | job1 | job2 | job3 | job4 | job5 | . . .
----------+------+------+------+------+------+------
1 | 20 | 10 | 5 | . | . | .
----------+------+------+------+------+------+------
2 | 10 | 13 | 5 | . | . | .
----------+------+------+------+------+------+------
Based on the added information, there are two main requirements here:
You want to sum up the time spent for producing each product grouped by the jobs involved
and
You want to have a cross-table report showing the times from step 1 against products and jobs.
For the first bit, you probably could do this with a query like this:
SELECT
p.product_id,
j.jobs,
SUM(j.time) as SUM_TIME
FROM
products p
INNER JOIN jobs j
ON p.jobs = j.jobs
GROUP BY
p.product_id,
j.jobs;
For the second part: this is usually called a PIVOT report.
SAP HANA does not provide a dynamic SQL command for generating output in this form (other DBMS have that).
However, this dynamic transformation is usually relevant for the data presentation and not so much for the processing.
So, as you probably want to use some form of front end for this report (e.g. MS Excel, Crystal Reports, Business Objects X, Tableau, ...) I would recommend doing the transformation and formatting in the frontend report. Look for "PIVOT" or "CROSSTAB" options to do that.

Nested Nears with Sphinx and Thinking_Sphinx

I have a RAILS 3.0.10 application (using Ruby 1.9.2) that using the thinking_sphinx gem. Is it possible in the extended match mode to use the "or" operator
with the "near" operator so that thinking_sphinx will find text with
either word in group 1 within a specified proximity to either word in
group 2. For example, '(pro | support | apologist | backer | stalwart
| proponent | patron | partisan | hero | leader | martyr | aimed |
stop) NEAR/30 people' ? I am using sphinx 0.9.9-release.
ThinkingSphinx.search "pro support apologist", :match_mode => :any