首页 \ 问答 \ 如何使用Cassandra数据库(cql)和node.js的简单示例(Simple example of how to use the Cassandra database (cql) and node.js)

如何使用Cassandra数据库(cql)和node.js的简单示例(Simple example of how to use the Cassandra database (cql) and node.js)

我试图查询并插入cassandra DB中的东西。 我知道如何在cql(cqlsh)的命令行中执行该操作,但不确定如何通过node.js与cassandra数据库进行基本交互。

如果有人可以给我非常简单的代码示例如何做到这一点,这将是非常有用的!

没有节俭,只允许node.js。

提前致谢。


I was trying to query and insert things into a cassandra DB. I know how to do that in the command line for cql (cqlsh), but was unsure on how to basically interact with the cassandra database through node.js.

If someone could give me very simple code examples of how to do this, it would be very useful!

Without thrift, only node.js is allowed.

Thanks in advance.


原文:https://stackoverflow.com/questions/22206917
更新时间:2023-09-25 12:09

最满意答案

我想,你想要reorder() 。 通常, reorder(x,y,FUN)根据将函数FUN应用于第二变量y的结果来改变因子x的级别的顺序。 在这种情况下,您可以使用FUN=length ,并且它对y使用什么并不重要。

设置数据(我选择修改概率以使结果更清晰):

set.seed(101)
df <- data.frame(Var1=as.factor(sample(c("AB", "BC", "CD", "DE", "EF"),
                            prob=c(0.1,0.5,0.2,0.05,0.15),
                                   1000, replace=TRUE)))

基本情节(错误的顺序):

library(ggplot2)
print(g1 <- ggplot(df, aes(x=factor(1), fill=Var1))+
   geom_bar(width=1, colour="black")+
   coord_polar(theta="y")+
   theme_void())

在这里输入图像描述

现在重新排序:

df$Var1 <- reorder(df$Var1,df$Var1,FUN=length)
levels(df$Var1)
## [1] "DE" "AB" "EF" "CD" "BC"

检查订单是否正确:

sort(table(df$Var1))
##  DE  AB  EF  CD  BC 
##  46 105 163 189 497 

打印新图(使用%+%粘贴新数据并使用guide_legend()翻转图例的顺序:也可以使用function(x) -length(x)作为FUN来更改guide_legend()的顺序第一名)。

print(g1 %+% df + 
    scale_fill_discrete(guide=guide_legend(reverse=TRUE)))

在这里输入图像描述


You want reorder(), I think. In general reorder(x,y,FUN) changes the order of levels of a factor x according to the results of applying function FUN to a second variable y. In this case, you can use FUN=length, and it doesn't really matter what you use for y.

Set up data (I chose to modify the probabilities to make the result clearer):

set.seed(101)
df <- data.frame(Var1=as.factor(sample(c("AB", "BC", "CD", "DE", "EF"),
                            prob=c(0.1,0.5,0.2,0.05,0.15),
                                   1000, replace=TRUE)))

Basic plot (wrong order):

library(ggplot2)
print(g1 <- ggplot(df, aes(x=factor(1), fill=Var1))+
   geom_bar(width=1, colour="black")+
   coord_polar(theta="y")+
   theme_void())

enter image description here

Now reorder:

df$Var1 <- reorder(df$Var1,df$Var1,FUN=length)
levels(df$Var1)
## [1] "DE" "AB" "EF" "CD" "BC"

Check that the order is right:

sort(table(df$Var1))
##  DE  AB  EF  CD  BC 
##  46 105 163 189 497 

Print the new plot (stick in the new data with %+% and flip the order of the legend with guide_legend(): you could also use function(x) -length(x) as FUN to change the order of the levels in the first place).

print(g1 %+% df + 
    scale_fill_discrete(guide=guide_legend(reverse=TRUE)))

enter image description here

相关问答

更多

相关文章

更多

最新问答

更多
  • 使用通配符获取更多servlet请求变量[重复](Get more servlet request variables using wildcards [duplicate])
  • 返回相同的集合类型,参数化不同(Returning same collection type, differently parameterised)
  • C ++朋友函数模板重载和SFINAE在clang ++,g ++,vc ++中的不同行为(C ++ 14模式)(C++ friend function template overloading and SFINAE different behaviors in clang++, g++, vc++ (C++14 mode))
  • 与paure IoT-Hub的Python paho-MQTT连接(Python paho-MQTT connection with azure IoT-Hub)
  • 编译器警告“来自不同的Objective-C类型的赋值”(Compiler warning “assignment from distinct objective-c type”)
  • C ++编译错误(在此函数中未初始化)[重复](C++ Compile Error (uninitialized in this function) [duplicate])
  • unsigned-signed下溢机制(unsigned-signed underflow mechanism)
  • 快速行查询的数据结构?(Data structure for fast line queries?)
  • 饥荒有手机安卓版的吗
  • Jquery可拖动碰撞检测错误(Jquery draggable collision detection bug)
  • sql调优是怎样来实现的?
  • 无法使占位符输入文本消失(Unable to make the placeholder input text disappear)
  • jQuery改变了两个div的CSS属性(JQuery change CSS property of two div's)
  • JDK中包含的库版本(Versions of libraries included in the JDK)
  • 请问下载的是出现ASP是什么意思
  • Firebase MLkit用于数字液晶显示器的文本识别(Firebase MLkit Text recognition for digital lcd displays)
  • 我可以在任何平台上运行C和C ++吗?(Can I run C and C++ on any platform?)
  • 让小组在C#的特定位置(get panel at specific positions in C#)
  • Nagios为通知设置了更高的间隔(Nagios set higher interval for notifications)
  • 无法向SMTP主机发送电子邮件(unable to send an email to SMTP host)
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何在.NET代码中验证全球邮政编码(How can I validate worldwide postal codes in my .NET code)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • Clojure:减少大型懒惰收集会占用内存(Clojure: Reducing large lazy collection eats up memory)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • 显示作为字符串的SVG(Showing an SVG that I have as a string)
  • 从jansson库里创建json请求的自由内存的正确方式是什么?(what is the proper way of free memory in creating json request from jansson libary?)
  • jQuery插件无法正常工作 - 它是附加的(jQuery plugin not working - it's appended)
  • 使用stat_summary自动调整ylim(Automatically adjusting ylim with stat_summary)