Exception while trying to execute Alter keyspace in cql - exception

I am new to cassandra. I have created a keyspace as the following
CREATE KEYSPACE sample WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': '1'
};
Now i want the properties of the keyspace to be altered so i execute the statement
alter keyspace sample with placement_strategy='org.apache.cassandra.locator.NetworkTopologyStrategy' AND stratey_options={DC1:1,DC2:0};
But i get the below error while trying to execute the statement
Bad Request: Failed parsing statement: [alter keyspace "sample" with placement_strategy='org.apache.cassandra.locator.NetworkTopologyStrategy' AND strategy_options={DC1:1,DCC2:0};] reason: NullPointerException null
Can someone please tell me the reason behind the error and the proper alter keyspace statement to make the changes to its properties?

If you are using Cassandra-2.0.x then the following alter command will work for you.
ALTER KEYSPACE sample WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 1, 'DC2' : 0 }
I think it will work for Cassandra-1.2.16 as well.

Related

How to use raw datatype DOUBLE(x, y) on Yii2 Migration

I use Yii2 DB Migration tool to make a double(17,3) column on my table
$this->createTable('{{%temp_transaction}}', [
'balance' => 'double(17,3) NOT NULL', // <-- will be DOUBLE() with no length
But I can do the alter using raw query on my DB directly
ALTER TABLE `temp_transaction` CHANGE `balance` `balance` DOUBLE(17,3) NOT NULL;
Is it a bug from Yii2 or I need to use other workaround? Thank you.

MySQL binding multiple parameters to a single query

I have a MySql database, and I'm connecting to it from a .Net app using Dapper. I have the following code:
await connection.ExecuteAsync(
"DELETE FROM my_data_table WHERE somedata IN (#data)",
new { data = datalist.Select(a => a.dataitem1).ToArray() },
trans);
When I do this with more than a single value, I get the following error:
MySqlConnector.MySqlException: 'Operand should contain 1 column(s)'
Is what I'm trying to do possible in MySql / Dapper, or do I have to issue a query per line I wish to delete?
Your original code was almost fine. You just need to remove the parentheses around the parameter. Dapper will insert those for you:
await connection.ExecuteAsync(
"DELETE FROM my_data_table WHERE somedata IN #data",
new { data = datalist.Select(a => a.dataitem1).ToArray() },
trans);

Exception in using bootstrap-storage-plugins.json file for storage plugin in apache-drill

I want to add storage plugins for MongoDB in apache-drill. After reading docs, I came to know that programmatically I can do that in two ways:
Rest API
using bootstrap-storage-plugins.json for configuration
I am using 2nd way for my java code.
Useful portion of my code:
Connection conn = new Driver().connect("jdbc:drill:zk=local",null);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("show databases");
while (rs.next())
{
String SCHEMA_NAME = rs.getString("SCHEMA_NAME");
System.out.println(SCHEMA_NAME);
}
bootstrap-storage-plugins.json:
{
"type": "mongo",
"connection": "mongodb://localhost:27017/",
"enabled": true
}
But on firing
"select * from mongo.testDB.`testCollection`";
I got following exception:
org.apache.calcite.sql.validate.SqlValidatorException
SEVERE: org.apache.calcite.sql.validate.SqlValidatorException: Table 'mongo.testDB.testCollection' not found
Aug 12, 2015 3:47:05 AM org.apache.calcite.runtime.CalciteException
SEVERE: org.apache.calcite.runtime.CalciteContextException: From line 1, column 15 to line 1, column 19: Table
'mongo.testDB.testCollection' not found
java.sql.SQLException: PARSE ERROR: From line 1, column 15 to line 1, column 19: Table 'mongo.testDB.testCollection' not found
bootstrap-storage-plugins.json is in my classpath. Do I need to provide and additional information?
Edit:
I tried show databases query and it's not showing schemas from MongoDB. It's only showing:
INFORMATION_SCHEMA
cp.default
dfs.default
dfs.root
dfs.tmp
sys
Your query looks like a query on the file system. Using the mongo storage plugin configuration, there's no workspace or file, so try making your query look like this:
SELECT * FROM testCollection;
Make sure you're using the right database name and your and collection is listed (SHOW DATABASES and SHOW TABLES).
This published correction of the Drill doc might help.

Submitting multiple query transactions in CFscript

I am having trouble finding the correct syntax to execute multiple MySQL statements at once, like with cftransaction. I'm trying to implement this in a CFC in pure cfscript.
<cftransaction>
DROP TABLE IF EXISTS SOME_TEMP_TBL;
CREATE TABLE SOME_TEMP_TBL AS
(
SELECT * FROM ANOTHER_TBL
);
DROP TABLE IF EXISTS SOME_TEMP_TBL_2;
CREATE TABLE SOME_TEMP_TBL_2 AS
(
SELECT * FROM ANOTHER_TBL_2
);
</cftransaction>
So I have the SQL statements chained together as a string:
var SQL = "
DROP TABLE IF EXISTS SOME_TEMP_TBL;
CREATE TABLE SOME_TEMP_TBL AS
(
SELECT * FROM ANOTHER_TBL
);
DROP TABLE IF EXISTS SOME_TEMP_TBL_2;
CREATE TABLE SOME_TEMP_TBL_2 AS
(
SELECT * FROM ANOTHER_TBL_2
);
";
And if I understand right I think I need to use a transaction {} block. But do I put raw MySQL code in there? Currently I'm trying to attach it to a Query object but Base.cfc (Railo) is throwing an error saying the datasource isn't defined.
transaction
{
qTrans = new Query();
qTrans.setSQL(SQL);
qTrans.execute();
qTrans.setDatasource(variables.instance.datasource.getDSN());
if (good)
{
transaction action="commit";
} else {
transaction action="rollback";
}
}
Have also tried just SQL.execute() but of course execute() isn't defined for a string & it wouldn't relate to any DB anyway...
Also, is the if(good) portion required? By default does if(good) test for whether or not a MySQL error occurred? And is transaction action="commit" what actually sends the SQL script?
Do I need to split these up into separate Query objects and run them sequentially? And if so what's the point of even having the transaction block in CFscript?
I know I'm way off here but I'm having a hard time navigating the CF documentation around this. If anyone knows of a good source specifically for CFscript references I could really use one, because I struggle with Adobe's version.
Try this code
try {
transaction {
qTrans = new Query();
qTrans.setDatasource(variables.instance.datasource.getDSN());
qTrans.setSQL(SQL);
qryRes = qTrans.execute();
TransactionCommit();
}
} catch(database e) {
TransactionRollback();
}

JPA native query for LONGTEXT field in a MySQL view results in error

I have the following JPA SqlResultSetMapping:
#SqlResultSetMappings({
#SqlResultSetMapping(name="GroupParticipantDTO",
columns={
#ColumnResult(name="gpId"),
#ColumnResult(name="gpRole"),
// #ColumnResult(name="gpRemarks")
}
)
Which is used like this:
StringBuilder sbQuery = new StringBuilder("Select ");
sbQuery.append(" gpId, ");
sbQuery.append(" gpRole, ");
// sbQuery.append(" gpRemarks ");
sbQuery.append(" FROM v_group_participants_with_details ");
Query query = em.createNativeQuery(sbQuery.toString(), "GroupParticipantDTO");
The view is like this:
DROP VIEW IF EXISTS `v_group_participants_with_details`;
CREATE VIEW `v_group_participants_with_details`
AS
SELECT
gp.id AS gpId,
gp.role AS gpRole,
gp.remarks AS gpRemarks
FROM GroupParticipation gp
;
The GroupParticipation table has the remarks column defined as LONGTEXT (I'm using Mysql 5.x)
Now for the problem:
When the remarks field is commented out from the query everything works perfectly, but if I try to include the remarks field in the query, I get the following error:
javax.persistence.PersistenceException: org.hibernate.MappingException:
No Dialect mapping for JDBC type: -1
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException
(AbstractEntityManagerImpl.java:614)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76)
What gives? How can I get a LONGTEXT column from a native query?
This problem is reported in HHH-1483 and HHH-3892. In short, Hibernate does not know, how to map a LONGVARCHAR column returned by a native query.
This problem is fixed in Hibernate 3.5.0+. For previous versions, a workaround would be to extend the MysqlDialect to register the correct Hibernate Type for a LONGVARCHAR:
import java.sql.Types;
import org.hibernate.Hibernate;
public class MyMySQL5Dialect extends org.hibernate.dialect.MySQL5Dialect {
public MyMySQL5Dialect() {
super();
// register additional hibernate types for default use in scalar sqlquery type auto detection
registerHibernateType(Types.LONGVARCHAR, Hibernate.TEXT.getName());
}
}