case5

hbaseContext.bulkPut[Row](rddFromSql.rdd,
      tableName,
      (putRecord) => {
        val put = new Put(Bytes.toBytes(putRecord.getString(0)))
        put.add(Bytes.toBytes(columnFamily1),Bytes.toBytes("receiver"),Bytes.toBytes(putRecord.getString(1)))
        put.add(Bytes.toBytes(columnFamily1),Bytes.toBytes("count"),Bytes.toBytes(putRecord.getLong(2)))
        put
      },
      true);
sc.textfile("/dir/*.txt")

df.first
res1: org.apache.spark.sql.Row = [blah1,blah2]
df.map { _.toSeq.map {_.toString}.toArray }.first
res2: Array[String] = Array(blah1, blah2)

Simplistic Java 8 code might look like this:

Files.write(
     Paths.get("some_file.txt"), 
     model.clusterCenters()
       .stream().map(a -> Arrays.toString(a.toArray()))
       .collect(Collectors.toList())
 );
Non Java 8 looked like this:

List<String> lines = new ArrayList<>();
for (Vector center : model.clusterCenters()) {       
   lines.add(Arrays.toString(center.toArray()));
}

Files.write(Paths.get("some_file.txt"), lines, Charset.defaultCharset());
### 含义 在C语言的`switch`语句中,多个`case`语句可以组合使用,若没有`break`语句,会出现“穿透现象”,即当表达式的值与某个`case`后的常量匹配时,会执行该`case`及后续所有`case`中的代码,直到遇到`break`语句或者`switch`语句结束。多个`case`语句(case 1、case 3、case 5case 7、case 8、case 10、case 12)通常用于对满足这些特定常量或值的情况执行相同的操作。比如在月份相关的场景中,这些月份为有 31 天的月份,可借此判断天数 [^1]。 ### 示例 ```c #include <stdio.h> int main() { int month; printf("请输入月份(1 - 12):"); scanf("%d", &month); switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: printf("该月有 31 天\n"); break; case 4: case 6: case 9: case 11: printf("该月有 30 天\n"); break; case 2: printf("该月平年有 28 天,闰年有 29 天\n"); break; default: printf("输入的月份无效!\n"); break; } return 0; } ``` 在这个示例里,当输入 1、3、5、7、8、10、12 这些月份时,程序会输出“该月有 31 天”,这是利用了`switch`语句的“穿透特性” [^1]。 ### 使用场景 - **月份天数判断**:如上述示例,依据输入的月份判断该月的天数。 - **状态判断**:在程序里,若有多个状态对应同一种处理逻辑,就可以使用多个`case`语句。例如,在游戏中,多个不同的关卡状态对应同一种奖励机制。 - **输入验证**:当需要验证用户输入的多个特定值是否有效时,可使用多个`case`语句进行判断。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值