Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

New events `row-first` and `row-last`

  • Loading branch information...
commit 404bcab93dbd014645c2c200909e33cb66272923 1 parent c496d75
Worms David authored November 22, 2011
18  README.md
Source Rendered
@@ -50,11 +50,19 @@ Available API
50 50
 
51 51
 ## Hive Query
52 52
 
53  
-The `client.query` function return an object similar to the 
54  
-[Readable Stream API][3]. At the moment, we have only implemented `pause` and 
55  
-`resume`.
  53
+The `client.query` function implement the [EventEmitter API][3].
56 54
 
  55
+The following events are emitted:
57 56
 
  57
+-   `row`
  58
+-   `row-first`
  59
+-   `row-last`
  60
+-   `error`
  61
+-   `end`
  62
+
  63
+The `client.query` functionreturn a Node [Readable Stream][4]. It is possible to 
  64
+pipe the data into a [Writable Stream][5] but it is your responsibility to emit
  65
+the `data` event, usually inside the `row` event.
58 66
 
59 67
 ## Raw versus sugar API
60 68
 
@@ -106,4 +114,6 @@ Here's an exemple using our sugar API
106 114
 
107 115
 [1]: http://hive.apache.org  "Apache Hive"
108 116
 [2]: http://thrift.apache.org  "Apache Thrift"
109  
-[3]: http://nodejs.org/docs/v0.6.2/api/streams.html#readable_Stream  "Readable Stream API"
  117
+[3]: http://nodejs.org/docs/v0.6.2/api/events.html#events.EventEmitter  "EventEmitter API"
  118
+[4]: http://nodejs.org/docs/v0.6.2/api/streams.html#readable_Stream  "Readable Stream API"
  119
+[5]: http://nodejs.org/docs/v0.6.2/api/streams.html#writable_Stream  "Writable Stream API"
2  lib/hive.coffee
@@ -49,10 +49,12 @@ module.exports.createClient = (options = {}) ->
49 49
                 return
50 50
             rows = rows.map (row) -> row.split '\t'
51 51
             for row in rows
  52
+                emitter.emit 'row-first', row, 0 if count is 0
52 53
                 emitter.emit 'row', row, count++
53 54
             if rows.length is size
54 55
                 fetch() unless emitter.paused
55 56
             else
  57
+                emitter.emit 'row-last', row, count - 1
56 58
                 emitter.readable = false
57 59
                 emitter.emit 'end'
58 60
         fetch = ->
1  package.json
@@ -7,6 +7,7 @@
7 7
         { "name": "David Worms", "email": "david@adaltas.com" }
8 8
     ],
9 9
     "dependencies": {
  10
+        "coffee-script": "latest",
10 11
         "thrift": "latest"
11 12
     },
12 13
     "devDependencies": {
22  test/QueryTest.coffee
@@ -34,16 +34,25 @@ module.exports =
34 34
                         next()
35 35
     'Query # all': (next) ->
36 36
         count = 0
  37
+        call_row_first = call_row_last = false
37 38
         client.query("SELECT * FROM #{table}")
38 39
         .on 'row', (row, index) ->
39 40
             assert.eql index, count
40 41
             count++
41 42
             assert.ok Array.isArray row
42 43
             assert.eql row.length, 3
  44
+        .on 'row-first', (row, index) ->
  45
+            assert.eql count, 0
  46
+            call_row_first = true
  47
+        .on 'row-last', (row, index) ->
  48
+            assert.eql count, 54
  49
+            call_row_last = true
43 50
         .on 'error', (err) ->
44 51
             assert.ok false
45 52
         .on 'end', ->
46 53
             assert.eql count, 54
  54
+            assert.ok call_row_first
  55
+            assert.ok call_row_last
47 56
             next()
48 57
     'Query # n': (next) ->
49 58
         count = 0
@@ -80,6 +89,19 @@ module.exports =
80 89
         .on 'end', ->
81 90
             assert.eql count, 54
82 91
             next()
  92
+    'Query # header': (next) ->
  93
+        # Test where hive.cli.print.header impact Thrift
  94
+        # answer is no
  95
+        count = 0
  96
+        client.execute 'set hive.cli.print.header=true', (err) ->
  97
+            query = client.query("select * from #{table}", 10)
  98
+            .on 'row', (row, index) ->
  99
+                count++
  100
+            .on 'error', (err) ->
  101
+                assert.ok false
  102
+            .on 'end', ->
  103
+                assert.eql count, 54
  104
+                next()
83 105
     'Close': (next) ->
84 106
         client.end()
85 107
         next()

0 notes on commit 404bcab

Please sign in to comment.
Something went wrong with that request. Please try again.