how can i manage this error? Mismatched input 'pair' expecting ')'.
I cannot remove all the brackets otherwise the message is not read by the binance api
strategy.entry ("RSILong", strategy.long , alert_message=" {"pair":"BTCUSDT","isBuy":true,"isSell":false,"isMarket":true,"isLimit":false,"isClose":false,"unitsPercent":"100","unitsType":"percentBalance","useTrailingStopLoss":false,"stopLossToBreakEven":false,"marginType":"ISOLATED","targets":[],"leverage":"125","closeCurrentPosition":true,"preventPyramiding":false,"reduceOnly":false,"limitPriceType":"fixedPrice","useDca":false,"dcaPercent":5,"token":"xxxxxxxx","exchange":"Binance-Futures","apiKey":"bin future"}" )
The quotes within the JSON string ({"pair":"BTCUSDT", ...) cause the mismatch.
Solution: Wrap the alert_message value in single quotes ' instead of double quotes ".
strategy.entry ("RSILong", strategy.long , alert_message='<your_json_string>' )
Related
I am trying to replace single quote in a string with double quote using replace function with data factory expressions.
For example, replace single quote in the following string
hello'world ---> hello''world
#replace(pipeline().parameters.tst,''','''')
The above code is not working. Need help in fixing the code
You can declare a new parameter with the value ' (single quote). You can look at the following demonstration for reference.
I have taken 2 parameters, text with the value hello'world and replace_char with the value '.
I used a set variable activity to store the output of the replace() function (for demonstration) into variable named output (String). Now, I modified the value as:
#replace(pipeline().parameters.text,pipeline().parameters.replace_char,'"')
This successfully helps in replacing a single quote with double quote character.
NOTE: The \ in the output variable value indicates that the " is to be considered as a character inside the string value.
Use two single quotes to escape a ' character in string functions.
For example, expression #concat('Baba', '''s ', 'book store') will return below result.
Baba's book store
https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions#escaping-single-quote-character
I'm trying to use PySpark's split() method on a column that has data formatted like:
[6b87587f-54d4-11eb-95a7-8cdcd41d1310, 603, landing-content, landing-content-provider]
my intent is to extract the 4th element after the last comma.
I'm using a syntax like:
mydf.select("primary_component").withColumn("primary_component_01",f.split(mydf.primary_component, "\,").getItem(0)).limit(10).show(truncate=False)
But I'm consistently getting this error:
"cannot resolve 'split(mydf.primary_component, ',')' due to data
type mismatch: argument 1 requires string type, however,
'mydf.primary_component' is of
structuuid:string,id:int,project:string,component:string
type.;;\n'Project [primary_component#17,
split(split(primary_component#17, ,)[1], \,)...
I've also tried escaping the "," using \, \\ or not escaping it at all and this doesn't make any difference. Also, removing the ".getItem(0)" produces no difference.
What am I doing wrong? Feeling a dumbass but I don't know how to fix this...
Thank you for any suggestions
You are getting the error:
"cannot resolve 'split(mydf.`primary_component`, ',')' due to data
type mismatch: argument 1 requires string type, however,
'mydf.`primary_component`' is of
struct<uuid:string,id:int,project:string,component:string>
because your column primary_component is using a struct type when split expects string columns.
Since primary_component is already a struct and you are interested in the value after your last comma you may try the following using dot notation
mydf.withColumn("primary_component_01","primary_component.component")
In the error message, spark has shared the schema for your struct as
struct<uuid:string,id:int,project:string,component:string>
i.e.
column
data type
uuid
string
id
int
project
string
component
string
For future debugging purposes, you may use mydf.printSchema() to show the schema of the spark dataframe in use.
I have a query that looks like this:
INSERT INTO table VALUES ('47677;2019;2019;10T-1001-10010AS;A05;International;TieLineKoman-KosovoB;L_KOM-KOSB;2018;NULL;NULL;;NULL;Tieline;NULL;10XAL-KESH-----J;0;3')
that is produced by parsing a csv file.
The query is not in a valid form, I have to replace all semicolons with the string ',' (comma inside single quotes). What I want to get is:
('47677','2019','2019','10T-1001-10010AS','A05','International','TieLineKoman-KosovoB','L_KOM-KOSB','2018','NULL','NULL','','NULL','Tieline','NULL','10XAL-KESH-----J','0','3')
I have tried to do this in many different ways, but I end up with backshlashes added in my string. This is what I get:
"INSERT INTO AllocatedEICDetail VALUES ('47677\\',\\'2019\\',\\'2019\\',\\'10T-1001-10010AS\\',\\'A05\\',\\'International\\',\\'TieLineKoman-KosovoB\\',\\'L_KOM-KOSB\\',\\'2018\\',\\'NULL\\',\\'NULL\\',\\'\\',\\'NULL\\',\\'Tieline\\',\\'NULL\\',\\'10XAL-KESH-----J\\',\\'0\\',\\'3')"
Any ideas how to do this properly without having the backslashes added?
Thank you!
//the string you have
const string = '47677;2019;2019;10T-1001-10010AS;A05;International;TieLineKoman-KosovoB;L_KOM-KOSB;2018;NULL;NULL;;NULL;Tieline;NULL;10XAL-KESH-----J;0;3';
//the string you need:
const targetString = string.replace(/\;/g,',');
You specify a small regex between the forward slashes in replace which is a simple ';', give it a 'g' flag for global which will replace all instances, and in the second argument supply what you need it replaced with.
I'm getting this message in Redshift: invalid input syntax for type numeric: " " , even after trying to implement the advice found in SO.
I am trying to convert text to number.
In my inner join, I try to make sure that the text being processed is first converted to null when there is an empty string, like so:
nullif(trim(atl.original_pricev::text),'') as original_price
... I noticed from a related post on coalesce that you have to convert the value to text before you can try and nullif it.
Then in the outer join, I test to see that there's a limited set of acceptable characters and if this test is met I try to do the to_number conversion:
,case
when regexp_instr(trim(atl.original_price),'[^0-9.$,]')=0
then to_number(atl.original_price,'FM999999999D00')
else null
end as original_price2
At this point I get the above error and unfortunately I can't see the details in datagrip to get the offending value.
So my questions are:
I notice that there is an empty space in my error message:
invalid input syntax for type numeric: " " . Does this error have the exact same meaning as
invalid input syntax for type numeric:'' which is what I see in similar posts??
Of course: what am I doing wrong?
Thanks!
It's hard to know for sure without some data and the complete code to try and reproduce the example, but as some have mentioned in the comments the most likely cause is the to_number() function you are using.
In the earlier code fragment you are converting original_price to text (string) and then substituting an empty string ('') if the value is NULL. Calling the to_number() function on an empty string will give you the error described.
Without the full SQL statement it's not clear why you're putting the nullif() function around the original_price in the "inner join" or how whether the CASE statement is really in an outer join clause or one of the columns returned by the query. However you could perhaps alter the nullif() to substitute a value that can be converted to a number e.g. '0.00' instead of ''.
Sorry I couldn't share real data. I spent the weekend testing small sets to try and trap the error. I found that the error was caused by the input string having no numbers, which is permitted by my regex filter:
when regexp_instr(trim(atl.original_price),'[^0-9.$,]') .
I wrongly expected that a non numeric string like "$" would evaluate to NULL and then the to_number function would = NULL . But from experimenting it seems that it needs at least one number somewhere in the string. Otherwise it reduces the string argument to an empty string prior to running the to_number formatting and chokes.
For example select to_number(trim('$1'::text),'FM999999999999D00') will evaluate to 1 but select to_number(trim('$A'::text),'FM999999999999D00') will throw the empty string error.
My fix was to add an additional regex to my initial filter:
and regexp_instr(atl.original_price2,'[0-9]')>0 .
This ensures that at least one number will be in the string and after that the empty string error went away.
Hope my learning experience helps someone else.
I have Customer.io account for emails which collects emails from test server.
There in an iframe where there needed elements. But I can't get to them. If I use:
page.in_iframe(xpath: "//iframe[contains(#class, 'ember-view')]") do |frame|
page.cell_element(xpath: "//td[contains(text(), 'Order Confirmation')]", frame: frame).when_present(30)
end
Then I get next error:
SyntaxError: (eval):1: syntax error, unexpected tIDENTIFIER, expecting ')'
.../iframe[contains(#class, 'ember-view')]').td(identifier)
... ^
(eval):1: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
...e[contains(#class, 'ember-view')]').td(identifier)
... ^
(eval):1: syntax error, unexpected ')', expecting end-of-input
...ntains(#class, 'ember-view')]').td(identifier)
...
And if I use this:
page.in_iframe(xpath: "//iframe[contains(#class, ember)]") do |frame|
page.cell_element(xpath: "//td[contains(text(), 'Order Confirmation')]", frame: frame).when_present(30)
end
Then I don't get this error but element couldn't be found.
One of the goals of Watir is to never have to use XPath.
Consider rewriting your locator with regular expressions like this:
#browser.iframe(class: /ember/).td(text: /Order Confirmation/)
The problem appears to be with the parsing of the iframe XPath string. I do not understand why the interpreter is having problems, but here are some solutions:
For the first example, switch to using single quotes as the outer part of the String:
page.in_iframe(xpath: '//iframe[contains(#class, "ember-view")]') do |frame|
page.cell_element(xpath: "//td[contains(text(), 'Order Confirmation')]", frame: frame).when_present(30)
end
For the second example, you do need to quote the attribute value. If you want to stick with double-quotes for the String, you can escape the inner double-quotes:
page.in_iframe(xpath: "//iframe[contains(#class, \"ember\")]") do |frame|
page.cell_element(xpath: "//td[contains(text(), 'Order Confirmation')]", frame: frame).when_present(30)
end
Alternatively, you might want to consider avoiding the XPath problem by using other locators:
page.in_iframe(class: 'ember-view') do |frame|
page.cell_element(text: /Order Confirmation/, frame: frame).when_present(30)
end
I've found another way:
#browser.iframe(xpath: "//iframe[contains(#class,'ember')]").td(xpath: "//td[contains(text(), 'Order Confirmation')]")
Because that examples don't want to work. Don't know why.
But thanks Justin: