Query tempview using JDBC (Sql server) - scala

I have a Temp view:
sales.createOrReplaceTempView("sales")
I want to use this tempView in a SQL server query:
select distinct
t2.id,
t1.prod
from prod t1
join sales t2 on t2.id = t1.id
The prod table (t1) is stored in sql server and sales table (t2) is a tempView.
How should I run this query? Is it possible to run this using JDBC?

Your Spark Application is running on a different cluster of machines out of which you are creating a temporary view. Your sql-server is running on a different machine and you created a table on it. These both components are speaking different languages of data. You can always connect them and bring either of these to the opposite platform and then work with the 2 tables/views on the common platform but you cannot simply join the tables on different platforms.

Related

Can't we join two tables and fetch data in Kafka?

I have joined two tables and fetched data using Postgres source connector. But every time it gave the same issue i.e.
I have run the same query in Postgres and it runs without any issue. Is fetching data by joining tables not possible in Kafka?
I solve this issue by using the concept of the subquery. The problem was that
when I use an alias, the alias column is interpreted as a whole as a column name and therefore the problem occurs. Here goes my query:
select * from (select p.\"Id\" as \"p_Id\", p.\"CreatedDate\" as p_createddate, p.\"ClassId\" as p_classid, c.\"Id\" as c_id, c.\"CreatedDate\" as c_createddate, c.\"ClassId\" as c_classid from \"PolicyIssuance\" p left join \"ClassDetails\" c on p.\"DocumentNumber\" = c.\"DocumentNo\") as result"

flink Table SQL Api

I want to know can we write query using two tables ( join) in flink Table and SQL api.
I am new to flik, I want to create two table from two different data set and query them and produce other dataset.
my query would be like select... from table1, table 2... so can we write like this query which querying two tables or more?
Thanks
Flink's Table API supports join operations (full, left, right, inner joins) on batch tables (e.g. those created from a DataSet).
SELECT c, g FROM Table3, Table5 WHERE b = e
For streaming tables (e.g. those created from a DataStream), Flink does not yet support join operations. But the Flink community is actively working to add them in the near future.

Teiid query optimization/ Virtual datasource jasper

I have a query like this:
Select A.table1.atr1, ... , B.table1.atr1
from A.table1
join B.table1 on (A.table1.atr1 = B.table1.atr2)
join B.table2 on (B.table1.atr2 = B.table2.atr2)
...(some similar joins)
join A.table2 on (A.table1.atr1 = A.table2.atr2)
where ...
A and B are jdbc datasources. I wonder how teiid handles multiple joins on the same database. Are they pushed down to the database? Is the join order between table A and B important? In my example i am using a join between A and B, then between B and B and then between A and A. Do i need to rearrange the order or to create 2 temporary tables on database A and database B?
If the database supports joins, yes they can be pushed down. During the planning of the query Teiid optimizer checks the capabilities of source and decides it can be pushed or need to process in Teiid engine. Based on it, it will re-write the query.

Is it possible to Union 6 Columns with different tables different database and different server?

Is it possible to Union 6 Columns with different tables different database and different server?
Please tell me if this is possible or not?
AS previous answer you need linked servers for a start.
When the servers have been added to your server where you are executing the query from you can run the query as follows
SELECT Field1 , field2
FROM LINKED_SERVER1.DatabaseName.dbo.tableName_X
UNION ALL
SELECT Field1 , field2
FROM LINKED_SERVER2.DatabaseName.dbo.tableName_Y
You can add as many tables to the union as you like, just following basic UNION rules. I.e all of the selects in the union must have the same number of fields, and of compatible datatypes
If you're looking to query across multiple databases on different servers using SQL Server, you should look at linked servers >> http://msdn.microsoft.com/en-us/library/ms188279.aspx
Once you've added all the linked servers you need to access, the tables on those servers can be accessed as if they were "local". Then you just need to worry about performance.

Feasibility of recreating complex SQL query in Crystal Reports XI

I have about 10 fairly complex SQL queries on SQL Server 2008 - but the client wants to be able to run them from their internal network (as opposed to from the non-local web app) through Crystal Reports XI.
The client's internal network does not allow us to (a) have write access to their proprietary db, nor (b) allow us to set up an intermediary SQL server (meaning we can not set up stored procedures or other data cleaning).
The SQL contains multiple instances of row_number() over (partition by col1, col2), group by col1, col2 with cube|rollup, and/or (multiple) pivots.
Can this even be done? Everything I've read seems to indicate that this is only feasible via stored procedure and I would still need to pull the data from the proprietary db first.
Following is a stripped back version of one of the queries (eg, JOINs not directly related to functionality, WHERE clauses, and half a dozen columns have been removed)...
select sum(programID)
, sum([a.Asian]) as [Episodes - Asian], sum([b.Asian]) as [Eps w/ Next Svc - Asian], sum([c.Asian])/sum([b.Asian]) as [Avg Days to Next Svc - Asian]
, etc... (repeats for each ethnicity)
from (
select programID, 'a.' + ethnicity as ethnicityA, 'b.' + ethnicity as ethnicityB, 'c.' + ethnicity as ethnicityC
, count(*) as episodes, count(daysToNextService) as episodesWithNextService, sum(daysToNextService) as daysToNextService
from (
select programID, ethnicity, datediff(dateOfDischarge, nextDateOfService) as daysToNextService from (
select t1.userID, t1.programID, t1.ethnicity, t1.dateOfDischarge, t1.dateOfService, min(t2.dateOfService) as nextDateOfService
from TABLE1 as t1 left join TABLE1 as t2
on datediff(d, t1.dateOfService, t2.dateOfService) between 1 and 31 and t1.userID = t2.userID
group by t1.userID, t1.programID, t1.ethnicity, t1.dateOfDischarge, t1.dateOfService
) as a
) as a
group by programID
) as a
pivot (
max(episodes) for ethnicityA in ([A.Asian],[A.Black],[A.Hispanic],[A.Native American],[A.Native Hawaiian/ Pacific Isl.],[A.White],[A.Unknown])
) as pA
pivot (
max(episodesWithNextService) for ethnicityB in ([B.Asian],[B.Black],[B.Hispanic],[B.Native American],[B.Native Hawaiian/ Pacific Isl.],[B.White],[B.Unknown])
) as pB
pivot (
max(daysToNextService) for ethnicityC in ([C.Asian],[C.Black],[C.Hispanic],[C.Native American],[C.Native Hawaiian/ Pacific Isl.],[C.White],[C.Unknown])
) as pC
group by programID with rollup
Sooooooo.... can something like this even be translated into Crystal Reports XI?
Thanks!
When you create your report instead of selecting a table or stored procedure choose add command
This will allow you to put whatever valid TSQL statement in there that you want. Using Common Table Expressions (CTE's) and inline Views I've managed to create some rather large complex statements (excess of 400 lines) against Oracle and SQL Server so it is indeed feasible, however if you use parameters you should consider using sp_executesql you'll have to figure out how to avoid SQL injection.