I am trying to use PreparedStatement with solr_query using the following code:
PreparedStatement preparedStatement = cassandraSession.prepare(
"SELECT * FROM users WHERE solr_query = 'username:? OR email:?';"
);
BoundStatement boundStatement = new BoundStatement(preparedStatement);
ResultSet results = cassandraSession.execute(
boundStatement.bind(
username,
email
)
);
When I execute the code above, I am getting the following exception:
java.lang.IllegalArgumentException: Prepared statement has only 0 variables, 2 values provided
How can I use prepared statements with solr_query properly?
I am using DataStax Enterprise 4.5.3 which uses Cassandra 2.0.11.82 and Solr 4.6.0.2.8. I am using the DataStax Java driver.
Sorry, but CQL does not support variable substitution within string constants, only for a complete string constant. The Solr query string is parsed again on every SELECT statement execution anyway, so having the Solr query string "prepared" would save no overhead, so you should simply supply the entire Solr query string as a prepared statement variable, as in "WHERE solr_query = ?".
Related
Create parameterize with Snowflake as like MySQL and SQL Server. Need to pass the values from .NET Snowflake .NET Connector.
https://www.mssqltips.com/sqlservertip/2981/using-parameters-for-sql-server-queries-and-stored-procedures/
Query with value:
select *
from "SNOWFLAKE_SAMPLE_DATA"."TPCDS_SF100TCL"."WEB_SITE"
where ((Web_REC_START_DATE is null and IFF('2000-08-16' is null,true,false))
or Web_REC_START_DATE > '2000-08-16')
How to use SqlDataReader with a parametrized query in c#?
Query with names of parameters:
select *
from "SNOWFLAKE_SAMPLE_DATA"."TPCDS_SF100TCL"."WEB_SITE"
where ((Web_REC_START_DATE is null and IFF(#StartDate is null,true,false))
or Web_REC_START_DATE > #StartDate)
the snowflake .net connector, is hosted in github, and it's read me describes how to in the bind-parameter section
so looking at the tests in the code, specifically the BindTest line 75
it shows named parameters being used. thus:
command.CommandText = "insert into TEST_TBL values(:p0)";
var param = command.CreateParameter();
param.ParameterName = "p0";
param.DbType = System.Data.DbType.Int32;
param.Value = DBNull.Value;
command.Parameters.Add(param);
I am trying to flatten an array using UNNEST function in the Table API.
Am I doing something wrong or it is not a supported function ? This page suggests it though: https://ci.apache.org/projects/flink/flink-docs-master/dev/table/sql/queries.html
Thanks !
Code
Python udf
#udf(input_types=DataTypes.STRING(), result_type=DataTypes.ARRAY(DataTypes.STRING()))
def explode(s):
return 3*[s]
t_env.register_function("explode", explode)
Processing
tab = t_env.from_path('mySource').select("id, explode(dummy) as dummy_list")
t_env.register_table("temp_table", tab)
t_env.sql_query("SELECT t.item as dummy_item FROM UNNEST(select dummy_list from temp_table) AS t(item)").insert_into("mySink")
Execution
t_env.execute("dummy_unnest")
Error
TableException: Cannot generate a valid execution plan for the given query:
LogicalProject(dummy_item=[$0])
Uncollect
LogicalProject(EXPR$0=[org$apache$flink$table$functions$python$PythonScalarFunction$908596b4671476ee325743dba92ed6c7($1)])
LogicalTableScan(table=[[default_catalog, default_database, mySource]])
This exception indicates that the query uses an unsupported SQL feature.
Please check the documentation for the set of currently supported SQL features.
I think you can change the query to
select id, dummy_item from temp_table CROSS JOIN UNNEST(dummy_list) AS t (dummy_item)
I am using DSE version = 5.0.1 . Using Solr for Search activities. I created core successfully for particular table.
After that once I am trying to execute solr seach query , I am getting below issue :-
cqlsh:tradebees_dev> SELECT * FROM yf_product_books where solr_query = ':';
ServerError: <Error from server: code=0000 [Server error]
message="java.io.IOException:
No shards available for ranges: [(2205014674981121837,2205014674981121837]]">
Please suggest some solutions.
Your query should be something like this : -
SELECT * FROM yf_product_books where solr_query = ':';
I am using spring data backed by hibernate for my project for the CRUD layer and ORM. I was using H2 first. But when switching to SQL server 2014, I faced the following issue:
I use the following service:
#Query("Select example from Example example where
example.exampleProperty like CONCAT('%',:param,'%')")
List<Example> findByProductLibe(#Param("param") String param);
To get Example object (from example table) using a property. It is working well in H2, but moving to sql server (by switching configuration channel AND Dialect to sql server) i have a BadSqlGrammarException due to the query generated by Hibernate is as follows:
Hibernate:
select
ex.param1 as param1,
ex.param2 as param2
from
example ex
where
example.exampleProperty like ('%'||?||'%')
the problem is with the '|' character, it prints 'Incorrect syntax near '|' '
Here is my database configuration:
database.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
database.password =
database.username =
hibernate.dialect = org.hibernate.dialect.SQLServerDialect
hibernate.ejb.naming_strategy = org.hibernate.cfg.ImprovedNamingStrategy
hibernate.hbm2ddl.auto = create
hibernate.generate_statistics = true
hibernate.format_sql = true
hibernate.show_sql = true
Thanks for any help or indication.
Replace with the below code in repo should work.
#Query("Select example from Example example where
example.exampleProperty like %:param%")
List<Example> findByProductLibe(#Param("param") String param);
Thank you for your answers, The problem is finally resolved, I made my hibernate.dialect to org.hibernate.dialect.SQLServer2012Dialect and it generated the following query:
Hibernate:
select
ex.param1 as param1,
ex.param2 as param2
from
example ex
where example.exampleProperty like ('%'+?+'%')
I must have not cleaned and install the project properly.
Thank you.
In my application I need to get database date(sysdate in case of Oracle DB) and compare it with user input date (String converted to java.util.Date). From this forum I got the following code which helps in the case of Oracle dialect.
public Date getDate() {
Session session = getHibernateTemplate().getSessionFactory().openSession();
SQLQuery query = session.createSQLQuery("select sysdate as mydate from dual");
query.addScalar("mydate", Hibernate.TIMESTAMP);
return (Date) query.uniqueResult();
}
And from this link got the following method which uses mapping file with formula.
<property name="currentDate" formula="(select sysdate from dual)"/>
Again this is specific to Oracle. I think using later method is more performance friendly, because we can get it from the same session, i.e no need of opening another session just for getting date.
I am looking for a generic solution to get date, time and timestamp from any DBMS using Hibernate. Using HQL is the preferred. Hope such a solution is available.
For those who are looking for .NET /C# solution, here is what worked for me:
// this works only with Oracle
public DateTime DbTimeStamp(ISession session)
{
// Sample returned value = "12-OCT-11 01.05.54.365134000 AM -07:00"
string sql = "SELECT SYSTIMESTAMP FROM DUAL";
ISQLQuery query = session.CreateSQLQuery(sql)
.AddScalar("SYSTIMESTAMP", NHibernate.NHibernateUtil.DateTime);
return query.UniqueResult<DateTime>();
}