Hi guys i have a question regarding this annoying error. Below it's my code
String updateDefaultBU = "update ClientUserVO set defaultBUnit = :yes where id = (select max(cu1.id) from ClientUserVO cu1 where cu1.user.id = :userId and cu1.defaultBUnit = :no)";
updateDefaultBU = " and not exists (select cu2.id from ClientUserVO cu2 where cu2.user.id = :userId and cu2.defaultBUnit = :yes) ";
Query updateQuery = session.createQuery(updateDefaultBU);
updateQuery.setString("yes", "Y");
updateQuery.setString("no", "N");
updateQuery.setLong("userId", userID);
I don't seem to understand where does it find a not that could not be traversed, also this error is very general and it could happen for various reasons, could you tell me what i am doing wrong?
Thanks
In your second assignment of updateDefaultBU you are changing the content of the variable completely and not concatenating with the first assignment (as I assume you want to do).
It is possible that you get the error because you run updateQuery.setString("no", "N") but the second assignment has no :no value in it.
Try changing the second line to updateDefaultBU.concat(" <your string> ")
Also have you tried to debug to see exactly where the error is happening?
Related
I'm trying to create a tubmbling window for a Flink table in Java and query data for that window
Table table = tEnv.sqlQuery(query.getQuery());
// create a new column 'EventTime' of type Timestamp from 'EventTimetamp' which is a string
table = table.addColumns($("EventTimestamp").toTimestamp().as("EventTime"));
WindowGroupedTable windowedTable = table.window(Tumble.over("10.minutes").on($("EventTime").proctime())
.as("w"))
.groupBy($("w"), $("GroupingColumn"));
table = windowedTable.select($("*"));
However, I'm getting this error Expected LocalReferenceExpression. Got: EventTime when it tries to execute windowedTable.select($("*")). Does anyone know what this error means and how to solve it ?
The problem is with .addColumns($("EventTimestamp") .
addCoumns() takes an expression as input. Take a look at the example from docs.
Table orders = tableEnv.from("Orders");
Table result = orders.addColumns(concat($("c"), "sunny"));
In this example, the column "c" already exists and you tell flink to concatane the value in column "c" with string "sunny" and add the new value as a new column.
So the meaning of your code
table.addColumns($("EventTimestamp")
in English is "select EventTimeStamp from table and add the values as a new column"
As your table does not have a column "EventTimestamp" yet, expression $("EventTimestamp") returns error.
EDIT: The problem might be related about ROWTIME. Please take a look at my answer using-tumble-failing-on-timestamp
Table tableCpuDataCalculatedTemp = tableEnv.fromDataStream(streamCPUData, Schema.newBuilder()
.column("deviceId", DataTypes.STRING())
.column("cpuUsageAvarage", DataTypes.DOUBLE())
.column("cpuLoad15Average", DataTypes.DOUBLE())
.column("recordCount", DataTypes.INT())
.column("time_Insert_ts", DataTypes.TIMESTAMP(3))
.watermark("time_Insert_ts", "time_Insert_ts")
.build());
I know there are some answers to this error. I know it's a syntax error, but can't fix it!!
I'm running these commands in a Pentaho transformation. They are from one DB to another.
SELECT emp, codlug, nombre, pais, pcia, codp FROM CONDOR.TCODLUG
order by codlug desc
select *
FROM CONDOR.TCABTRAN o138195,
CONDOR.TCRES o138205,
CONDOR.TCCTES o138234,
CONDOR.TITEMS o138320,
CONDOR.TPDC o138351,
CONDOR.TPROV o138355,
CONDORBI.VRENTRAN o138514,
CONDOR.TROCCONT o138537
WHERE ( (o138195.EMP = o138514.EMP AND o138195.CODTRAN = o138514.CODTRAN AND o138195.NUMTRAN = o138514.NUMTRAN)
and (o138205.EMP(+) = o138514.EMP AND o138205.UNORG1(+) = o138514.UNORG1 AND o138205.UNORG2(+) = o138514.UNORG2 AND o138205.UNORG3(+) = o138514.UNORG3)
and (o138234.EMP(+) = o138514.EMP AND o138234.CODCC(+) = o138514.CODCC AND o138234.NUMCC(+) = o138514.NUMCC)
and (o138320.CODITEM(+) = o138537.CODITEM)
and (o138351.CTACONT = o138514.CTACONT)
and (o138355.EMP(+) = o138537.EMP AND o138355.NUMPROV(+) = o138537.NUMPROV)
and (o138537.EMP(+) = o138514.EMP AND o138537.CODTRAN(+) = o138514.CODTRAN AND o138537.NUMTRAN(+) = o138514.NUMTRAN AND o138537.RENGLON(+) = o138514.RENGLON))
AND ((DECODE(o138351.ACRES,1,'C.Res',NULL)) = 'C.Res')
-- AND (o138514.CTACONT BETWEEN :"Cuenta Desde" AND :"Cuenta Hasta")
-- AND (o138514.FECREG BETWEEN :"Desde" AND :"Hasta")
-- AND (o138514.EMP = :"Empresa")
When I run the transformation it throws the syntax error:
java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
i´ve already search but can´t find a proper answer.
THNAKS!!!
You can have only one statement in the input table.
Well, you can have more, provided that they are separated by ";". However only the last one will produce rows in the output. (This feature is there to make temporary tables or procedures to execute on the last statement).
If you want a union, and do not want to do it in sql, then make two table input steps and drop those two in the same PDI step. You'll get an error if the metadata (column names, order and types) are not the same.
I have a scenario where there are two sheets(csv). Created two tables for it.
When there s a good data I could map it with a value( id statistic value) from the second table. If I have bad data I should map it with id statistic value again (but a different value). however, I'm unable to use not exists in spark SQL. And I get the error below:
mismatched input 'from' expecting {, 'WHERE', 'GROUP', 'ORDER', 'HAVING', 'LIMIT', 'LATERAL', 'WINDOW', 'UNION', 'EXCEPT', 'INTERSECT', 'SORT', 'CLUSTER', 'DISTRIBUTE'}(line 1, pos 386)
at org.apache.spark.sql.catalyst.parser.ParseException.withCommand(ParseDriver.scala:197)
at org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parse(ParseDriver.scala:99)
at org.apache.spark.sql.execution.SparkSqlParser.parse(SparkSqlParser.scala:45)
CODE:
select
a.ptf_id,a.ptf_code,a.share_id,a.share_code,a.bench_id,a.bench_code
, a.l1_calculation_date,a.l1_begin_date,a.l1_end_date,a.l1_running_date
, a.l1_frequency,a.l1_calculation_step,a.l1_performance_currency
, a.l1_configuration,a.l1_valuation_source,a.l1_nav_valuation_type
, a.l1_setting_reference_type, a.l1_setting_valuation_type
, a.l1_sharpe_ratio_annualized as value,b.id_statistic
from
parquetFile a,
pairRDD b,
stats c
where
a.l1_nav_valuation_type= b.l1_nav_valuation_type
and a.l1_valuation_source = b.l1_valuation_source
and b.l1_Perf = 'l1_sharpe_ratio_annualized'
OR (a.ptf_id not EXISTS (
select e.ptf_id from pairRDD d, parquetFile e
where d.l1_valuation_source = e.l1_valuation_source
AND d.l1_nav_valuation_type = e.l1_nav_valuation_type)
and b.l1_valuation_source ='')
this query works in SQL if I use "NOT in"
please help me on what other options to use in this scenario other than not exists.
The query is a bit hard to follow as written. It's not clear (to me anyway) what your intentions are for the stats table since you don't select anything from it so I removed it. Obviously I haven't tried this myself but at a glance, you might try something like this instead:
select
a.PTF_ID,
a.PTF_CODE,
a.SHARE_ID,
a.SHARE_CODE,
a.BENCH_ID,
a.BENCH_CODE,
a.L1_CALCULATION_DATE,
a.L1_BEGIN_DATE,
a.L1_END_DATE,
a.L1_RUNNING_DATE,
a.L1_FREQUENCY,
a.L1_CALCULATION_STEP,
a.L1_PERFORMANCE_CURRENCY,
a.L1_CONFIGURATION,
a.L1_VALUATION_SOURCE,
a.L1_NAV_VALUATION_TYPE,
a.L1_SETTING_REFERENCE_TYPE,
a.L1_SETTING_VALUATION_TYPE,
a.L1_SHARPE_RATIO_ANNUALIZED as VALUE,
b.ID_STATISTIC
from
PARQUETFILE a
inner join
PAIRRDD b
on
a.L1_NAV_VALUATION_TYPE = b.L1_NAV_VALUATION_TYPE and
a.L1_VALUATION_SOURCE = b.L1_VALUATION_SOURCE
left outer join (
select
e.PTF_ID
from
PAIRRDD d
inner join
PARQUETFILE e
on
d.L1_VALUATION_SOURCE = e.L1_VALUATION_SOURCE AND
d.L1_NAV_VALUATION_TYPE = e.L1_NAV_VALUATION_TYPE
where
b.L1_VALUATION_SOURCE = ''
) x
on
a.PTF_ID = x.PTF_ID
where
b.L1_PERF = 'l1_sharpe_ratio_annualized' or
x.PTF_ID is null
I'm trying to perform an sql query as so:
select * from conversations where (user_1 = user_1_id and user_2 = user_2_id ) or (user_1 = user_2_id and user_2 = user_1_id )
I'm writing it in Ebean as so:
Conversation conversation = Ebean.find(Conversation.class)
.where()
.and(Expr.eq("user_1", user_1_id), Expr.eq("user_2", user_2_id))
.or(Expr.eq("user_1", user_2_id), Expr.eq("user_2", user_1_id))
.findUnique();
However this gives the following query:
select * from conversation where (user_1 = user_1_id and user_2 = user_2_id ) and (user_1 = user_2_id or user_2 = user_1_id )
I've been looking at the documentation, but I'm not getting a clear idea about how to refine the query to match my needs.
Can anyone help?
Have a look at the JavaDoc (it has an or expression as an example):
// Example: Using an Expr.or() method
Query<Order> query = Ebean.createQuery(Order.class);
query.where(
Expr.or(Expr.eq("status", Order.NEW),
Expr.gt("orderDate", lastWeek));
List<Order> list = query.findList();
This perhaps makes it a bit easier to understand why this code:
.or(Expr.eq("user_1", user_2_id), Expr.eq("user_2", user_1_id))
Results in:
(user_1 = user_2_id or user_2 = user_1_id )
You are, so to speak, using the or expression inside your second condition, instead of between the two conditions.
You need to put the or method first:
Conversation conversation = Ebean.find(Conversation.class)
.where().or(
Expr.and(Expr.eq("user_1", user_1_id), Expr.eq("user_2", user_2_id)),
Expr.and(Expr.eq("user_1", user_2_id), Expr.eq("user_2", user_1_id)))
.findUnique();
This should put the or between your paranthesises, and an and condition inside them.
Can someone please tell me how to get a Text value out of a Google App Engine datastore using Java? I have some entities in the datastore with a Text property named longDescription. When I try this:
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Query q = new Query("Items");
PreparedQuery pq = ds.prepare(q);
for (Entity result : pq.asIterable()) {
Text longDescription = (Text)result.getProperty("longDescription");
}
I'm getting this warning on the longDescription assignment line:
WARNING: /pstest
java.lang.ClassCastException: java.lang.String cannot be cast to
com.google.appengine.api.datastore.Text
I'm absolutely bumfuzzled here. The only string in my code is the literal "longDescription" that is used to fetch the correct property. If I put this just above the assignment line:
log.warning("Type is " + (result.getProperty("longDescription")).getClass());
I see the following output:
WARNING: Type is class com.google.appengine.api.datastore.Text
Okay, so result.getProperty("longDescription") really, really is a Text object that is being passed back as an object. I've even tried using the fully qualified name (com.google.appengine.api.datastore.Text) instead of just Text with the same results. Where is the String cast coming in? And more importantly, how do I get that Text out of the datastore? I'm at my wit's end here, and any help would be appreciated!
Oh, one other possibly relevant note: This is the assignment I used when inserting the property into the datastore:
Entity eItem = new Entity("Items");
eItem.setProperty("longDescription", new Text(req.getParameter("ldes")));
ds.put(eItem);
When I look at the description in my management console, it seems to be over 500 characters, and it's displayed like this:
<Text: This is a long form description of an item in the store that is access...>
Did I screw something up when inserting it? If so, how do you insert Text items into the datastore?
I figured out the problem, Wei Hao was right in the comments above. It seems that at some point, I inserted a test String as a longDescription instead of a Text. I'm going to chalk this up to being a lesson learned from the school of hard knocks due to being a bit of a noob with the datastore.
For anyone else who runs across this question, the answer is: If you're iterating over a list of query results, make sure that you're getting back what you expect on every result that comes back! Remember, this isn't an RDBMS and every entity can have a different datatype for the same property. So yes, you can have 1,572,394 entities in which longDescription is a Text and one entity in which longDescription is a String, and this will hose you up.
Here's a little code snippet that probably would help to diagnose this issue:
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Query q = new Query("Items");
PreparedQuery pq = ds.prepare(q);
for (Entity result : pq.asIterable()) {
if (longDescription isinstanceof Text)
Text longDescription = (Text)result.getProperty("longDescription");
else
log.severe("Unexpected datatype: longDescription is a "
+ result.getProperty("longDescription").getClass().toString());
}
Here's my code;
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Query q = new Query(entityKind);
PreparedQuery pq = ds.prepare(q);
for (Entity e : pq.asIterable()) {
String longtext = ((Text)e.getProperty("somelongdescription")).getValue();}