Skip to content

Instantly share code, notes, and snippets.

@sakama
Last active June 16, 2016 08:15
Show Gist options
  • Save sakama/b00919a80d6f3e08d990bc34e3aaec34 to your computer and use it in GitHub Desktop.
Save sakama/b00919a80d6f3e08d990bc34e3aaec34 to your computer and use it in GitHub Desktop.
embulk-input-mongodbの型調査

##Example Data

> db.version();
3.0.10

> db.test.find();
{
  "_id" : ObjectId("573a9d37efb32df843124db9"),
  "account" : 32864,
  "time" : ISODate("2015-01-25T13:23:15Z"),
  "purchase" : "2015-02-15",
  "comment" : "embulk jruby",
  "boolean_column" : false,
  "double_column" : 3.141592,
  "array_column" : [ "apple", "banana", "peach" ],
  "json_column" : { "c1" : 1.23, "c2" : 20000, "c3" : 123 }
}

ValueCodecのdecodeメソッドに以下の行を追加

  String fieldName = reader.readName();
  BsonType type = reader.getCurrentBsonType();
+ log.info(String.format("field_name:'%s',type:'%s'", fieldName, type.toString()));
  if (type == BsonType.OBJECT_ID) {
      isTopLevelNode = true;
  }

実行

$ embulk run /path/to/config.yml
2016-06-16 16:56:43.778 +0900 [INFO] (0018:task-0000): field_name:'_id',type:'OBJECT_ID'
2016-06-16 16:56:43.778 +0900 [INFO] (0018:task-0000): field_name:'account',type:'INT32'
2016-06-16 16:56:43.778 +0900 [INFO] (0018:task-0000): field_name:'time',type:'DATE_TIME'
2016-06-16 16:56:43.779 +0900 [INFO] (0018:task-0000): field_name:'purchase',type:'STRING'
2016-06-16 16:56:43.779 +0900 [INFO] (0018:task-0000): field_name:'comment',type:'STRING'
2016-06-16 16:56:43.779 +0900 [INFO] (0018:task-0000): field_name:'boolean_column',type:'BOOLEAN'
2016-06-16 16:56:43.780 +0900 [INFO] (0018:task-0000): field_name:'double_column',type:'DOUBLE'
2016-06-16 16:56:43.780 +0900 [INFO] (0018:task-0000): field_name:'array_column',type:'ARRAY'
2016-06-16 16:56:43.781 +0900 [INFO] (0018:task-0000): field_name:'json_column',type:'DOCUMENT'
2016-06-16 16:56:43.782 +0900 [INFO] (0018:task-0000): field_name:'c1',type:'DOUBLE'
2016-06-16 16:56:43.782 +0900 [INFO] (0018:task-0000): field_name:'c2',type:'INT32'
2016-06-16 16:56:43.782 +0900 [INFO] (0018:task-0000): field_name:'c3',type:'INT32'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment