首页 \ 问答 \ 谁能写一个简单的单例模式?

谁能写一个简单的单例模式?

更新时间:2023-07-17 18:07

最满意答案

Configuration conf = HBaseConfiguration.create();
  String tableName = "testTable";
  Scan scan = new Scan();
  scan.setCaching(10000);
  scan.setCacheBlocks(false);
  conf.set(TableInputFormat.INPUT_TABLE, tableName);
  ClientProtos.Scan proto = ProtobufUtil.toScan(scan);
  String ScanToString = Base64.encodeBytes(proto.toByteArray());
  conf.set(TableInputFormat.SCAN, ScanToString);
  JavaPairRDD

  myRDD = sc
  .newAPIHadoopRDD(conf, TableInputFormat.class,
  ImmutableBytesWritable.class, Result.class);
  在Spark使用如上Hadoop提供的标准接口读取HBase表数据(全表读),读取5亿左右数据,要20M+,而同样的数据保存在Hive中,读取却只需要1M以内,性能差别非常大。
  转载,仅供参考。

其他回答

必须使用高亮参数启动spark-shell,否则当你遍历rdd时会出现如下的exception
java.io.notserializableexception: org.apache.hadoop.hbase.io.immutablebyteswritable
spark-shell--conf spark.serializer=org.apache.spark.serializer.kryoserializer
以下代码,经过maprdb实测通过
import org.apache.spark._
import org.apache.spark.rdd.newhadooprdd
import org.apache.hadoop.hbase.{hbaseconfiguration, htabledescriptor}
import org.apache.hadoop.hbase.client.hbaseadmin
import org.apache.hadoop.hbase.mapreduce.tableinputformat
import org.apache.hadoop.fs.path;
import org.apache.hadoop.hbase.hcolumndescriptor
import org.apache.hadoop.hbase.util.bytes
import org.apache.hadoop.hbase.client.put;
import org.apache.hadoop.hbase.client.htable;
val tablename = "/app/subscriptionbillingplatform/transac_id"
val conf = hbaseconfiguration.create()
conf.set(tableinputformat.input_table, tablename)
//create rdd
val hbaserdd = sc.newapihadooprdd(conf, classof[tableinputformat], 
  classof[org.apache.hadoop.hbase.io.immutablebyteswritable],
  classof[org.apache.hadoop.hbase.client.result])
hbaserdd.take(2).map(row=>row._2.rawcells).
      map(_.map( kv => (new string(kv.getqualifier()) -> new 
string(kv.getvalue()) ) ).tomap ).     foreach( map => { map.foreach{
 entry => print(entry._1 +":" + entry._2 + ", ")  } ; 
print("\n-----------\n") }  )       
//get the row count
val count = hbaserdd.count()
print("hbase rdd count:"+count)

相关问答

更多
  • 必须使用高亮参数启动Spark-shell,否则当你遍历RDD时会出现如下的Exception java.io.NotSerializableException: org.apache.hadoop.hbase.io.ImmutableBytesWritable spark-shell--conf spark.serializer=org.apache.spark.serializer.KryoSerializer 以下代码,经过MaprDB实测通过 import org.apache.spark._ im ...
  • Configuration conf = HBaseConfiguration.create();   String tableName = "testTable";   Scan scan = new Scan();   scan.setCaching(10000);   scan.setCacheBlocks(false);   conf.set(TableInputFormat.INPUT_TABLE, tableName);   ClientProtos.Scan proto = ProtobufU ...
  • 使用Spark(Scala)读取HBase数据的基本示例,您还可以使用Java来描述这一点: import org.apache.hadoop.hbase.client.{HBaseAdmin, Result} import org.apache.hadoop.hbase.{ HBaseConfiguration, HTableDescriptor } import org.apache.hadoop.hbase.mapreduce.TableInputFormat import org.apache.ha ...
  • Spark与HBase集成,数据局部性原理与Hadoop map-reduce作业相同:spark会尝试将输入分区(hbase region)分配给同一台物理机器上的worker,因此数据将直接在没有远程驱动程序的情况下获取。 Spark is integrated with HBase and data locality principles are the same as in Hadoop map-reduce jobs: spark will try to assign input partitio ...
  • Splice Machine(开源)有一个演示火花流运行的演示。 http://community.splicemachine.com/category/tutorials/data-ingestion-streaming/ 以下是此用例的示例代码。 https://github.com/splicemachine/splice-community-sample-code/tree/master/tutorial-kafka-spark-streaming Splice Machine (Open Sour ...
  • 1)在HBASE之上将Spark分层而不是仅使用HBASE带来了哪些附加功能? 它只取决于程序员的能力,还是有任何性能原因可以做到这一点? Spark有什么东西可以做,HBASE完全不能做? 在Splice Machine,我们使用Spark在HBase之上进行分析。 HBase没有执行引擎,spark在HBase(中级结果,关系代数等)之上提供了一个称职的执行引擎。 HBase是一个MVCC存储结构,Spark是一个执行引擎。 它们是彼此的天然补充。 2)从上一个问题出发,何时应该在HDFS和SPARK之 ...
  • 你可以按照下面的例子 import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.ZooKeeperConnectionException; im ...
  • 好吧显然这是一个意想不到的依赖问题(因为它始终没有任何意义)。 这些是我为解决这个问题而采取的步骤(希望它们能帮助未来的开发人员): 我使用完全相同的代码创建了一个干净的项目。 这没有任何问题立即让我怀疑它是某种依赖性问题 为了确保,我将HBase依赖项放在依赖项的顶部。 这创建了一个与Spark和安全性相关的异常,更具体地说:javax.servlet.FilterRegistration 然后我遇到了这个有用的解决方案,为我解决了这个问题。 我不得不从我的pom中排除所有的javax和mortbay码头 ...
  • 那么这对我来说只是一个愚蠢的错误,我感觉有点愚蠢。 按字母顺序排列,顺序应该是1,10,2,3 ... 8,9。在装载之前保证正确顺序的最简单方法是: rdd.sortByKey(true); 我希望至少能救一个人头痛。 Well this was just a silly error on my part, and I feel a bit foolish. Lexicographically, the order should be 1, 10, 2, 3... 8, 9. Easiest way t ...
  • foreachRDD在个别执行程序jvm进程上执行。 至少你可以在transferToHBasePut方法中获得conf的单例实例(意味着在使用现有的jvm进程集合或新的conf之前进行空值检查)。 因此,这将减少Hbase与Spark群集中生成的执行程序数量的连接数。 希望这可以帮助... foreachRDD executes on individual executors jvm process. At least you can get the singleton instance of conf( ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。