Google fusiontables sql OR clause - google-visualization

I m trying the sample at
https://developers.google.com/fusiontables/docs/samples/gviz_datatable
In the query, instead of
query += " WHERE 'Scoring Team' = '" + team + "'";
i tried to add another OR condition...
query += " WHERE 'Scoring Team' = '" + team + "' or 'Receiving Team'='Mexico' ";
This would return an error
While if i use AND
query += " WHERE 'Scoring Team' = '" + team + "' and 'Receiving Team'='Mexico' ";
There would not return error.
Why would the OR condition return error?
Any idea? Thanks!

The OR - operator is not supported by the FusionTables-API.
It may be hard to believe, but that's how it is.

Related

AWS adaptor with Spring Cloud function - payload body is removed

I am building a AWS lambda function using Spring cloud, aws adapter and spring native.
The lambda is fronted by a APIGateway HTTP API V2.0.
<java.version>11</java.version>
<spring-cloud.version>2021.0.2</spring-cloud.version>
<spring-native.version>0.11.4</spring-native.version>
<aws-lambda-events.version>3.9.0</aws-lambda-events.version>
<wrapper.version>1.0.27.RELEASE</wrapper.version>here
When I hit the API with the cloud function pointing to echo function, I get a response with the body of the request removed!
I setup below test to debug the issue. Found that the below highlighted code from
org.springframework.cloud.function.adapter.aws.AWSLambdaUtils
is causing the issue. I see that the highlighted line is removed in the 4X branch. Request to kindly guide how to incorporate that fix into my project while staying on the release version of the dependencies.
public static void main(String[] args) {
String message = "{\r\n"
+ " \"version\": \"2.0\",\r\n"
+ " \"routeKey\": \"POST /updatePet\",\r\n"
+ " \"rawPath\": \"/updatePet\",\r\n"
+ " \"rawQueryString\": \"\",\r\n"
+ " \"headers\": {\r\n"
+ " \"accept\": \"*/*\",\r\n"
+ " \"accept-encoding\": \"gzip, deflate, br\",\r\n"
+ " \"content-length\": \"77\",\r\n"
+ " \"content-type\": \"application/json\",\r\n"
+ " \"host\": \"XXXXXX.execute-api.ap-south-1.amazonaws.com\",\r\n"
+ " \"postman-token\": \"2004009f-2661-46ea-9a31-2d6be0bb9281\",\r\n"
+ " \"user-agent\": \"PostmanRuntime/7.29.0\",\r\n"
+ " \"x-amzn-trace-id\": \"Root=1-62823410-XXXXXXXXXXXXX\",\r\n"
+ " \"x-forwarded-for\": \"111.11.111.111, 111.111.111.111\",\r\n"
+ " \"x-forwarded-port\": \"443\",\r\n"
+ " \"x-forwarded-proto\": \"https\"\r\n"
+ " },\r\n"
+ " \"requestContext\": {\r\n"
+ " \"accountId\": \"123456733\",\r\n"
+ " \"apiId\": \"xxxxx\",\r\n"
+ " \"domainName\": \"xxxxxx.execute-api.ap-south-1.amazonaws.com\",\r\n"
+ " \"domainPrefix\": \"vaoo36b2l5\",\r\n"
+ " \"http\": {\r\n"
+ " \"method\": \"POST\",\r\n"
+ " \"path\": \"/updatePet\",\r\n"
+ " \"protocol\": \"HTTP/1.1\",\r\n"
+ " \"sourceIp\": \"1.1.1.1\",\r\n"
+ " \"userAgent\": \"PostmanRuntime/7.29.0\"\r\n"
+ " },\r\n"
+ " \"requestId\": \"SN0SoioabccwEJuQ=\",\r\n"
+ " \"routeKey\": \"POST /updatePet\",\r\n"
+ " \"stage\": \"$default\",\r\n"
+ " \"time\": \"16/May/2022:11:22:56 +0000\",\r\n"
+ " \"timeEpoch\": 1652700176657\r\n"
+ " },\r\n"
+ " \"body\": \"{\\r\\n\\\"id\\\":1,\\r\\n\\\"name\\\":\\\"toto\\\",\\r\\n\\\"type\\\":\\\"dog\\\",\\r\\n\\\"owner\\\":{\\\"name\\\":\\\"test\\\",\\\"age\\\":8}\\r\\n}\",\r\n"
+ " \"isBase64Encoded\": false\r\n"
+ "}";
Message<byte[]> msg = AWSLambdaUtils.generateMessage(message.getBytes(StandardCharsets.UTF_8), headers(), String.class, mapper());
var payload = new String(msg.getPayload(),StandardCharsets.UTF_8);
System.out.println("payload is"+payload);
}

Why won't my function execute

I'm relatively new to python and the only other experience I've had is C++. Whenever I define a function in Python, I can't seem to execute it.
This my current code for my assignment, if possible I just want to know why my code won't execute
def birthexp(birthyear):
product = birthyear**birthyear
length = len(str(product))
onesCount = str(product).count("1")
threeCount = str(product).count("3")
fiveCount = str(product).count("5")
sevenCount = str(product).count("7")
nineCount = str(product).count("9")
sumCount = onesCount+threeCount+fiveCount+sevenCount+nineCount
oneRation = onesCount/float(length)*100
threeRatio = threeCount/float(length)*100
fiveRatio = fiveCount/float(length)*100
sevenRatio = sevenCount/float(length)*100
nineRatio = nineCount/float(length)*100
totalRatio = sumCount/float(length)*100
print(str(product) + ": product after multiplying the birth year to itself.")
print(str(onesCount) + ": number of ones found at a rate of " +str(oneRation)+ "percent.")
print(str(threeCount) + ": number of threes found at a rate of " +str(threeRatio)+ "percent")
print(str(fiveCount) + ": number of fives found at a rate of " +str(fiveRatio)+ "percent")
print(str(sevenCount) + ": number of sevens found at a rate of " +str(sevenRatio)+ "percent")
print(str(nineCount) + ": number of nine found at a rate of " +str(nineRatio)+ "percent")
print(str(sumCount) + ": total odd numbers found at a rate of " +str(totalRatio)+ "percent")
birthyear(1990)
You have a typo in this line totalRatio = sumCount/floar(length)*100. You need float instead of floar.
Secondly, you have loads of missing parenthesis in almost all lines with the print function.
If you want the function to return value, you should use return instead of print's:
return (str(product)
+ ": product after multiplying the birth year to itself.\n"
+ str(onesCount)
+ ": number of ones found at a rate of " + str(oneRation) + "percent.\n"
+ str(threeCount)
+ ": number of threes found at a rate of " + str(threeRatio) + "percent\n"
+ str(fiveCount)
+ ": number of fives found at a rate of " + str(fiveRatio) + "percent\n"
+ str(sevenCount)
+ ": number of sevens found at a rate of " + str(sevenRatio) + "percent\n"
+ str(nineCount)
+ ": number of nine found at a rate of " + str(nineRatio) + "percent\n"
+ str(sumCount)
+ ": total odd numbers found at a rate of " + str(totalRatio) + "percent\n")

Speed up MySQL Update - InnoDB

I wouldn't think an update of 22*1000 values of type DOUBLE should take ~4 seconds. However that is what I am getting. The following is query is done 22 times. Perhaps this is actually on par? It doesn't satisfy my speed requirements then.
UPDATE [some table] SET [some column] = (CASE WHEN [column1] = i THEN [some number]
concatenated through i=1:1:1000, ending with END);
This statement takes ~4/22 seconds.
Remedies I have tried:
Lock table before update, and unlock after.
Thoughts to help(yet to try):
Reduce update into smaller update queries.
Additional Info:
Engine: InnoDB,
C++ Connector
EDIT 1
Code Excerpt:
Query ="LOCK TABLES CANS_SQL.SortingIndices WRITE;";
stmt = con->createStatement();
bool LOCKBIT = stmt->execute(Query);
delete stmt;
Query.clear();
Query = "UPDATE SortingIndices SET " + Objects.at(Typ).GetMetricNames().at(ObjMetIndex) + "_KVector = ( CASE ";
for (int k = 0; k<kvector.size()-1; k++)
{
while(true)
{
if(InsertCount<KvectorInsertPos.size())
{
if (KvectorInsertPos.at(InsertCount)==k)
{
Query += "WHEN Sort_ID = " + std::to_string(k+1+InsertCount) + " THEN " + std::to_string(KvectorInsertVal.at(InsertCount)+InsertCount) + " ";
InsertCount++;
}
else
break;
}
else
break;
}
Query += "WHEN Sort_ID = " + std::to_string(k+1+InsertCount) + " THEN " + std::to_string(kvector.at(k)+InsertCount) + " ";
}
while(true)
{
if(InsertCount<KvectorInsertPos.size())
{
if (KvectorInsertPos.at(InsertCount)==kvector.size()-1)
{
Query += "WHEN Sort_ID = " + std::to_string(kvector.size()+InsertCount) + " THEN " + std::to_string(KvectorInsertVal.at(InsertCount)+InsertCount) + " ";
InsertCount++;
}
else
break;
}
else
break;
}
Query += "WHEN Sort_ID = " + std::to_string(kvector.size()+InsertCount) + " THEN " + std::to_string(kvector.at(kvector.size()-1)+InsertCount) + " END ) ";
stmt = con->createStatement();
stmt->executeUpdate(Query);
delete stmt;
EDIT 2
Example Query:
Query = "UPDATE SortingIndices
SET X_Centroid_Sort_Index = (CASE
WHEN Sort_ID = 1 THEN 1.4324
WHEN Sort_ID = 2 THEN 4.234
WHEN Sort_ID = 3 THEN 324
...
WHEN Sort_ID = 1000 THEN 232.4 END);

Path is wrong, what to do?

I'd like to write something to my path.
My code is following
QString Log::logPacketsPath = QDir::currentPath() + "/logs/Packets/";
int userID = 1;
QString text = "test 1 2 3";
QFile logPacketFile(logPacketsPath + "UserID: " + userID + " - " + QDateTime::currentDateTime().toString("dd.MM.yy") + ".log");
if (logPacketFile.open(QFile::WriteOnly | QFile::Text | QFile::Append))
{
QTextStream out(&logPacketFile);
out << "[" << QDateTime::currentDateTime().toString("dd.MM.yy, hh:mm:ss") << "]: " << text << "\n";
logPacketFile.close();
}
But it only creates the file named "UserID" with nothing in it.
Do you know where the mistake is?
I'm not sure which OS you're using, but ':' is invalid in a Windows filename.
Next, you should flush the QTextStream before closing the file:
out.flush();
logPacketFile.close();
or create additional scope:
{
QTextStream out(&logPacketFile);
out << "[" << QDateTime::currentDateTime().toString("dd.MM.yy, hh:mm:ss") << "]: " << text << "\n";
}
logPacketFile.close();
Also, as Chemobyl has pointed out, you can get into trouble by concatinating the int userID to your filepath. I'd suggest using string formatting to create the filename:
QString logPacketFile("%1UserID%2 - %3.log")
.arg(logPacketsPath)
.arg(userID)
.arg(QDateTime::currentDateTime().toString("dd.MM.yy"));
Convert int to QString:
Use QString::number().
Output with your current code:
"C:/.../logs/Packets/UserID [bad symbols here] - 17.11.14.log"
Output with
QFile logPacketFile(logPacketsPath + "UserID " + QString::number(userID) + " - " + QDateTime::currentDateTime().toString("dd.MM.yy") + ".log");//removed colon
is:
"C:/.../logs/Packets/UserID 1 - 17.11.14.log"
It is source of big troubles. See next:
int userID = 70;
QString text = "test 1 2 3";
QFile logPacketFile(logPacketsPath + "UserID " + userID + " - " + QDateTime::currentDateTime().toString("dd.MM.yy") + ".log");
Output:
.../UserID F - 17.11.14.log"
Note F, not a 70 because operator+ thought that you use simple char and 70 in char is F:
http://www.asciitable.com/
So I strongly suggest you to use QString::number to prevent errors.

Try catch trouble in netbeans

I'm trying to create a search engine that gets information from my SQL database. Right now I'm struggling to make the combobox and textfield work. So far I can only make the first part of the code work, it allows the user to search for a name in the database. The rest however doesn't work at all, resulting in just an empty window where the info should pop up.
Here are some translations of the Swedish words present in the code:
Namn - Name
sokt - Searched
ANSTALLD - Employee
Aid - Employee id
telefon - phone
try
{
if(jComboBoxSokAID.getSelectedItem().equals("Namn"))
{
String namn = jTextFieldSokText.getText();
String namnQuery = "select * from ANSTALLD where namn = '" + namn + "'";
try
{
HashMap <String, String> soktNamn = idb.fetchRow(namnQuery);
jTextAreaSpecialistInfo.setText("Namn: " + soktNamn.get("namn") + "\n" + "Aid: " + soktNamn.get ("aid") + "\n" + "Telefon: " + soktNamn.get ("telefon") + "\n" + "Mail: " + soktNamn.get ("mail"));
if(jComboBoxSokAID.getSelectedItem().equals("Mail"))
{
String mail = jTextFieldSokText.getText();
String mailQuery = "select * from ANSTALLD where mail = '" + mail + "'";
try
{
HashMap <String, String> soktMail = idb.fetchRow(mailQuery);
jTextAreaSpecialistInfo.setText("Namn: " + soktMail.get("namn") + "\n" + "Aid: " + soktMail.get ("aid") + "\n" + "Telefon: " + soktMail.get ("telefon") + "\n" + "Mail: " + soktMail.get ("mail"));
if(jComboBoxSokAID.getSelectedItem().equals("Telefon"))
{
String telefon = jTextFieldSokText.getText();
String telefonQuery = "select * from ANSTALLD where telefon = '" + telefon + "'";
try
{
HashMap <String, String> soktTelefon = idb.fetchRow(telefonQuery);
jTextAreaSpecialistInfo.setText("Namn: " + soktTelefon.get("namn") + "\n" + "Aid: " + soktTelefon.get ("aid") + "\n" + "Telefon: " + soktTelefon.get ("telefon") + "\n" + "Mail: " + soktTelefon.get ("mail"));
if(jComboBoxSokAID.getSelectedItem().equals("AID"))
{
String AID = jTextFieldSokText.getText();
String AIDQuery = "select * from ANSTALLD where aid = '" + AID + "'";
try
{
HashMap <String, String> soktAID = idb.fetchRow(AIDQuery);
jTextAreaSpecialistInfo.setText("Namn: " + soktAID.get("namn") + "\n" + "Aid: " + soktAID.get ("aid") + "\n" + "Telefon: " + soktAID.get ("telefon") + "\n" + "Mail: " + soktAID.get ("mail"));
}
catch (InformatikException e)
{
if(jComboBoxSokAID == null)
jTextAreaSpecialistInfo.setText("Sökningen gav inga resultat");
}
}
}
catch (InformatikException e)
{
}
}
}
catch (InformatikException e)
{
}
}
}
catch (InformatikException e)
{
}
Don't write code this way.
Never have empty catch blocks.
I prefer to have a single try/catch in a method. Nesting them this way is an indication that you ought to refactor a method that's doing too much.
You've mingled persistence and UI code together in the worst way possible. Tease them apart so you can test and use them separately.
You don't close any database resources. This will come to grief.