单个Mapper类可以在一次运行中生成多个键值对(相同类型)吗?
我们在mapper中输出键值对,如下所示:
context.write(key, value);
Run Code Online (Sandbox Code Playgroud)
这是Key的精简版(和示例版):
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.ObjectWritable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;
public class MyKey extends ObjectWritable implements WritableComparable<MyKey> {
public enum KeyType {
KeyType1,
KeyType2
}
private KeyType keyTupe;
private Long field1;
private Integer field2 = -1;
private String field3 = "";
public KeyType getKeyType() {
return keyTupe;
}
public void settKeyType(KeyType keyType) {
this.keyTupe = keyType;
}
public Long getField1() {
return field1;
}
public void setField1(Long field1) {
this.field1 = field1;
} …Run Code Online (Sandbox Code Playgroud) 刚刚完成一个大型的Appengine mapreduce任务,我的许多分片都在终点线上被卡住了.这是设置:
filenames = yield mapreduce_pipeline.MapperPipeline(
'example mapper name',
'main.MyMapper',
input_reader_spec='mapreduce.input_readers.DatastoreInputReader',
output_writer_spec='mapreduce.output_writers.FileOutputWriter',
params={
'input_reader':{
'entity_kind':'models.MyModel'
},
'output_writer':{
'filesystem':'gs',
'mime_type':'text/csv',
'gs_bucket_name':'myBucket',
'output_sharding':'input'
}
},
shards=DUMP_SHARDS
)
Run Code Online (Sandbox Code Playgroud)
我正在并行运行其中的3个,每个都有16个分片.一个映射器完成没有问题,另外两个映射器在其14和9个分片上取得了成功.
剩下的碎片都完全是石墙,然后返回UnknownError: ApplicationError: 7.(本文末尾的完整堆栈跟踪.)
请注意,映射器正在尝试写入Google云端存储.执行此写操作的位发生错误.
狩猎了一段时间后,我发现,在google.appengine.runtime.apiproxy(这似乎是有问题的代理),该错误7 OTHER_ERROR.
我一直在重试这些最终任务(从任务队列中)大约3个小时,自从这些错误开始以来没有一个成功; 无论发生什么,它都完全陷入困境.我也尝试停止运行的所有实例,以防它是一些奇怪的本地状态,但没有改变......
这是完整的堆栈跟踪:
I 2012-12-13 15:40:23.909
Processing done for shard 14 of job '1582444192075C233F6AA'
E 2012-12-13 15:40:23.969
ApplicationError: 7
Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ …Run Code Online (Sandbox Code Playgroud) python google-app-engine mapreduce mapper google-cloud-storage
当我在阅读本幻灯片中有关延迟公平调度的内容时,我对Hadoop中的"作业调度"和"任务调度"这两个术语感到困惑.
如果我在以下假设中出错,请纠正我:
默认调度程序,容量调度程序和公平调度程序仅在用户调度多个作业时在作业级别有效.如果系统中只有单个作业,它们不起任何作用.这些调度算法构成了"作业调度"的基础
每个作业都可以有多个map和reduce任务以及它们如何分配给每台机器?如何为单个工作安排任务?"任务调度"的基础是什么?
我有两个与mapreduce和hadoop相关的概念疑问.我知道一个简单的迭代map-reduce程序,知道mapper,reducer,shuffler是什么..但是仍然想知道以下问题
1)什么时候迭代地图减少完成?
2)我知道身份映射器/减速器给出与馈送输入相同的输出.但是我们什么时候使用身份映射器/缩减器?
有一个具有默认参数的案例类Person.
传递mapper一个缺少param的字符串,mapper将其设置为null.
期望它设置默认值
为什么是这样 ?
例如:
@JsonIgnoreProperties(ignoreUnknown = true)
case class Person(id:Int,name:String="")
class MapperTest extends SpecificationWithJUnit {
"Mapper" should {
"use default param" in {
val personWithNoNameString = """{"id":1}"""
val mapper = new ObjectMapper();
mapper.registerModule(DefaultScalaModule)
val personWithNoName = mapper.readValue(personWithNoNameString,classOf[Person])
personWithNoName.name must be("")
}
}
}
Run Code Online (Sandbox Code Playgroud)
得到错误:
'null' is not the same as ''
java.lang.Exception: 'null' is not the same as ''
Run Code Online (Sandbox Code Playgroud) 我找到了几个如何将自定义ResultHandler连接到MyBatis查询的示例:
例如https://code.google.com/p/mybatis/wiki/ResultHandlerExample
不幸的是,示例中给出的ResultHandler永远不会被调用.(正如最后的评论已经说明的那样)
所以我搜索了一个解决方案,发现了这个:MyBatis - ResultHandler没有被调用
但这并不适合我的问题,因为我使用的是MyBatis xml风格的方式而不是API风格的方式.所以在我的情况下,我没有
SqlSession session = MyBatisConnectionFactory.getSqlSessionFactory().openSession(true);
Run Code Online (Sandbox Code Playgroud)
有没有办法在xml文件中连接我的自定义处理程序,例如<resultMap />oder <select />节点?
我已经在Swift编写了一段时间,我想我必须放一个!我没有立即定义的所有let字段变量.
现在我注意到这段代码没有编译,我真的很惊讶?为什么是这样?
class MyClass : Mapper {
var a: Bool!
required init?(_ map: Map) {
}
// Mappable
func mapping(map: Map) {
a <- map["a"]
}
}
let myClass = MyClass()
if myClass.a { // Compiler not happy
// Optional type 'Bool!' cannot be used as a boolean; test for '!= nil' instead
}
if true && myClass.a { // Compiler happy
}
if myClass.a && myClass.a { // Compiler happy
}
Run Code Online (Sandbox Code Playgroud)
Apple Swift 2.2版
编辑
有些人指出为什么我使用一个let永远不会改变的变量.我提到它是用于字段变量,但我缩短了示例.使用ObjectMapper(http://github.com/Hearst-DD/ObjectMapper …
我一直试图让我的头围绕适配器模式,在所有模式中,我最难想象它的用途.
我想我明白了实现了什么,对我而言,它是将对象转换为另一个接口,以便客户端可以使用它.
在示例中,我看到它们有意义,但我觉得我可以使用一个映射器实现相同的功能,该映射器接受一个对象并将其属性(也可能应用一些逻辑)映射到所需的对象类型,因此使用真实对象.
是否存在差异,或者它们的名称是否相同?
这是我的Model类
//Model
public class CustomerData {
private String locomotive_id;
private String customer_name;
private String road_number;
private String locomotive_type_code;
private String in_service_date;
private String part_number;
private String emission_tier_type;
private String airbrake_type_code;
private String lms_fleet;
private String aar_road;
private String locomotive_status_code;
// Getters and Setters
Run Code Online (Sandbox Code Playgroud)
这是我的RowMapper实现
//RowMapper
public class CustomerDataResponseMapper implements RowMapper {
@Override
public Object mapRow(ResultSet rs, int count) throws SQLException {
CustomerData customerData = new CustomerData();
customerData.setLocomotive_id(rs.getString("locomotive_id"));
customerData.setCustomer_name(rs.getString("customer_name"));
customerData.setRoad_number(rs.getString("road_number"));
customerData.setLocomotive_type_code(rs.getString("locomotive_type_code"));
customerData.setIn_service_date(rs.getString("in_service_date"));
customerData.setPart_number(rs.getString("part_number"));
customerData.setEmission_tier_type(rs.getString("emission_tier_type"));
customerData.setAirbrake_type_code(rs.getString("airbrake_type_code"));
customerData.setLms_fleet(rs.getString("lms_fleet"));
customerData.setAar_road(rs.getString("aar_road"));
customerData.setLocomotive_status_code(rs.getString("locomotive_status_code"));
return customerData;
} …Run Code Online (Sandbox Code Playgroud) 我有一个字符串格式的有效 UUID
7a041f81-1214-41e5-bb58-9a46b2ca08d4
Run Code Online (Sandbox Code Playgroud)
但是当我使用 aObjectMapper将其转换为 UUID 时,我不断收到此错误。
UUID uuid = mapper.readValue("7a041f81-1214-41e5-bb58-9a46b2ca08d4",UUID.class);
Run Code Online (Sandbox Code Playgroud)
错误:
com.fasterxml.jackson.core.JsonParseException:意外的字符('a'(代码 97)):预期的空格分隔根级别值 [来源:(字符串)“7a041f81-1214-41e5-bb58-9a46b2ca08d4”;行:1,列:3] 在 com.xxxx.yyyyy.zzzzz.Test.callTest(BmcEventListenerTest.java:22
如何将字符串转换为 UUID?为什么我不断收到此错误?