Cassandra 是无模式的吗?

Is Cassandra schema-less?

我正在使用 NodeJS 应用程序连接到 Cassandra cassandra-driver

玩过 cassandra-driver 之后,我注意到我们已经预先为每个 table 定义了架构。 谁能帮我理解是否每个 table 的架构都需要事先在 Cassandra 中定义?

以下是我尝试从我的 nodeJS 应用程序连接到 Cassandra DB 的方式:

const cassandra = require("cassandra-driver");
const client = new cassandra.Client({
 contactPoints: ['127.0.0.1'],
 localDataCenter: 'datacenter1',
 keyspace: 'testdb'
});

const executeCassandraQuery = async (query, params) => {
let fetchData;
try {
    fetchData = await client.execute(query, params, { prepare: false });
    console.log(`Successfully executed the query: ${JSON.stringify(fetchData)}`);
} catch (error) {
    console.log(`There was an error executing the query: ${error}`)
}
return fetchData;
}

client.connect(async function (err, data) {
if (err) {
    console.log(`There was an error connecting to Cassandra...${err}`)
}
else {
    console.log(`Connected to Cassandra...${data}`);
    const insertQuery = 'INSERT INTO testtable (id, firstname, lastname) VALUES(?,?,?)';
    const insertQueryParams = [1, "Tony", "Mathew"];

    const insertQueryResponse = await executeCassandraQuery(insertQuery, insertQueryParams);
    console.log(`insertQueryResponse : ${insertQueryResponse}`);
    const fetchQuery = 'SELECT * FROM employees';
}
});  

在 运行 上述 nodeJS 脚本之前,我使用以下 cql 命令创建了 'testdb' 键空间和 'testtable' table:

CREATE KEYSPACE testdb WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};
CREATE TABLE testtable(id int PRIMARY KEY, name text);

不,不是 schema-less。

相关答案适用:

相关文字:

No, not any more. This used to be possible. It required the old (pre-3.x storage engine) and use of a Thrift-based API. But tables built with CQL (and the new storage engine) require all columns to be defined-up front, and do not allow it at runtime (at least, not in the same way that Thrift did).