Hadoop后端有数百万条记录插入(Hadoop backend with millions of records insertion)
我是hadoop的新手,有人可以建议我如何将数百万条记录上传到hadoop吗? 我可以用蜂巢做到这一点,我在哪里可以看到我的hadoop记录?
到目前为止,我已经使用配置单元在hadoop上创建数据库,我使用localhost 50070访问它。但是我无法将数据从csv文件加载到终端的hadoop。 因为它给了我错误:
FAILED:语义分析出错:第2行:0无效路径''/ user / local / hadoop / share / hadoop / hdfs'':没有匹配路径的文件hdfs:// localhost:54310 / usr / local / hadoop / share / Hadoop的/ HDFS
有谁能建议我解决它的方法?
I am new to hadoop, can someone please suggest me how to upload millions of records to hadoop? Can I do this with hive and where can I see my hadoop records?
Until now I have used hive for creation of the database on hadoop and I am accessing it with localhost 50070. But I am unable to load data from csv file to hadoop from terminal. As it is giving me error:
FAILED: Error in semantic analysis: Line 2:0 Invalid path ''/user/local/hadoop/share/hadoop/hdfs'': No files matching path hdfs://localhost:54310/usr/local/hadoop/share/hadoop/hdfs
Can anyone suggest me some way to resolve it?
原文:https://stackoverflow.com/questions/32835802
最满意答案
关于“哪些文件已加载到分区”:
- 如果您使用了
EXTERNAL TABLE
并且只是将原始数据文件上传到映射到LOCATION
的HDFS目录中,那么您可以(a)从命令行在该目录上运行
hdfs dfs -ls
(或使用等效的Java API调用)(b)运行Hive查询,例如select distinct INPUT__FILE__NAME from (...)
- 但在您的情况下,您将数据复制到“托管”表中,因此无法检索数据沿袭(即用于创建每个托管数据文件的日志文件)
- ...除非你在日志文件中明确添加原始文件名,当然(在“特殊”标题记录上,或在每个记录的开头 - 可以使用旧的
sed
)
关于“如何自动避免INSERT上的重复”:有一种方法,但它需要相当多的重新设计,并且会花费你的处理时间/(额外的Map步骤加MapJoin)/ ...
- 将日志文件映射到
EXTERNAL TABLE
以便您可以运行INSERT-SELECT查询- 使用
INPUT__FILE__NAME
伪列作为源将原始文件名上载到托管表中添加一个
WHERE NOT EXISTS
子句w /相关子查询,这样如果源文件名已经存在于目标中,那么你不再加载
INSERT INTO TABLE Target SELECT ColA, ColB, ColC, INPUT__FILE__NAME AS SrcFileName FROM Source src WHERE NOT EXISTS (SELECT DISTINCT 1 FROM Target trg WHERE trg.SrcFileName =src.INPUT__FILE__NAME )
注意实际需要的愚蠢的DISTINCT,以避免在Mappers中吹掉RAM; 对于像Oracle这样成熟的DBMS来说它会毫无用处,但是Hive优化器仍然相当粗糙......
About "which files have been loaded in a partition":
- if you had used an
EXTERNAL TABLE
and just uploaded your raw data file in the HDFS directory mapped toLOCATION
, then you could(a) just run a
hdfs dfs -ls
on that directory from command line (or use the equivalent Java API call) (b) run a Hive query such asselect distinct INPUT__FILE__NAME from (...)
- but in your case, you copy the data into a "managed" table, so there is no way to retrieve the data lineage (i.e. which log file was used to create each managed datafile)
- ...unless you add explicitly the original file name inside the log file, of course (either on "special" header record, or at the beginning of each record - which can be done with good old
sed
)
About "how to automagically avoid duplication on INSERT": there is a way, but it would require quite a bit of re-engineering, and would cost you in terms of processing time /(extra Map step plus MapJoin)/...
- map your log file to an
EXTERNAL TABLE
so that you can run an INSERT-SELECT query- upload the original file name into your managed table using
INPUT__FILE__NAME
pseudo-column as sourceadd a
WHERE NOT EXISTS
clause w/ correlated sub-query, so that if the source file name is already present in target then you load nothing more
INSERT INTO TABLE Target SELECT ColA, ColB, ColC, INPUT__FILE__NAME AS SrcFileName FROM Source src WHERE NOT EXISTS (SELECT DISTINCT 1 FROM Target trg WHERE trg.SrcFileName =src.INPUT__FILE__NAME )
Note the silly DISTINCT that is actually required to avoid blowing away the RAM in your Mappers; it would be useless with a mature DBMS like Oracle, but the Hive optimizer is still rather crude...
相关问答
更多-
关于“哪些文件已加载到分区”: 如果您使用了EXTERNAL TABLE并且只是将原始数据文件上传到映射到LOCATION的HDFS目录中,那么您可以 (a)从命令行在该目录上运行hdfs dfs -ls (或使用等效的Java API调用)(b)运行Hive查询,例如select distinct INPUT__FILE__NAME from (...) 但在您的情况下,您将数据复制到“托管”表中,因此无法检索数据沿袭(即用于创建每个托管数据文件的日志文件) ...除非你在日志文件中明确添加原始文件名,当 ...
-
是的,你确实可以做到这一点......创建一个新类并使其成为SQLConnection类型的对象或者它是什么。 它的目的应该是创建和维护与数据库的连接并执行各种任务(这部分是可选的,因为您可以直接传入查询)。 从网上得到这个 class DBConnect { private MySqlConnection connection; private string server; private string database; private string uid; p ...
-
避免重复密钥/数据(Avoiding duplication of key/data)[2022-03-30]
这个问题有些主观。 创建应用程序时,我通常会尝试执行以下操作: 从不在多个地方定义相同的数据。 来源应该始终是明确的 如果我需要创建任何索引以便更快/更容易访问,我使用实用程序方法来执行此操作。 那些方法应该进行适当的单元测试,这样我就不会怀疑他们做错了什么 尽可能使用第三方库(例如已经建议的lodash或下划线)以最小化要编写/维护的代码量。 如果您的算法和实用程序经过适当的单元测试,您不必担心(太多)将数据置于不一致状态。 但是,如果这些是非常重要的系统/接口,您可以在输出上添加一些验证。 在输入上进行 ... -
Capistrano是一个跨服务器自动执行任务的工具,它完全符合您的要求。 它是用Ruby编写的,使用SSH与其他机器通信。 Capistrano is a tool for automating tasks across servers, it does exactly what you ask. It's written in Ruby and uses SSH to communicate with the other machines.
-
最常见的解决方案是使用乐观锁定 。 它归结为向您的实体添加version列,使用@Version注释。 每次提交之前,Hibernate都会检查version ,如果数据库中的版本比正在保存的实体的版本新,则会抛出异常。 The most common solution is to use optimistic locking. It comes down to adding a version column to your entities, annotated with @Version. versio ...
-
您需要使用RSA对其进行加密,因为使用RSAProtectedConfigurationProvider,您可以跨服务器复制密钥。 网络农场场景 您可以在Web场中使用RSA加密, 因为您可以导出RSA密钥 。 如果在将Web.config文件中的数据部署到Web场中的其他服务器之前对其进行加密,则需要执行此操作。 在这种情况下,必须导出解密数据所需的私钥并将其部署到其他服务器。 使用RSA提供程序加密Web场中Web.config中的连接字符串 为此, 您必须创建自定义RSA加密密钥容器,并在Web场中的 ...
-
在Amazon Web服务或Windows Azure之上构建您的应用程序,让他们担心这一点,因为它相当复杂。 Build your app on top of Amazon Web services or Windows Azure and let them worry about this since it's fairly complex.
-
我没有用服务器完成它,但我用文件连接完成了这个。 而不是数据流,从每个循环开始,循环遍历服务器列表,并从您在此循环中填充的变量设置连接。 然后将数据流放在循环任务中。 I haven't done it with servers but I have done this with file connections. Instead of a data flow, start with a For each loop that will loop through a list of servers and s ...
-
数据如何在多个Linux服务器间同步[关闭](How data can be synchronized among multiple linux servers [closed])[2024-02-25]
您可以将数据库中的复制用于您的目的。 You can use replication in database for your purpose. -
我可以为服务器创建一个类并运行多次 是。 只需在构造函数中提供不同的HashMap数据。 您必须以不同的名称在注册表中注册所有三个实例,或者通过其他一些RMI机制访问它们。 与@ JunedAhsan的回答相反,他们都可以共享相同的TCP端口,默认情况下,如果它们都是从同一个JVM导出的,那么就没有理由不这样做。 Could I create one class for servers and run multiple times Yes. Just supply the different HashMap ...