Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Comment multiple line with empty '--' as well as with '/*, '*/' signs

  • Loading branch information...
commit 52bff2b029e8d9996ac0e523a11ac636905cee92 1 parent 309f7d0
@wdavidw authored
View
20 lib/hive.coffee
@@ -8,7 +8,25 @@ EventEmitter = require('events').EventEmitter
split = module.exports.split = (hqls) ->
return hqls if Array.isArray hqls
- hqls = hqls.split('\n').filter( (line) -> line.trim().indexOf('--') isnt 0 ).join('\n')
+ commented = false
+ hqls = hqls.split('\n').filter( (line) ->
+ line = line.trim()
+ skip = false
+ if not commented and line.indexOf('/*') isnt -1
+ commented = '/*'
+ skip = true
+ else if not commented and line is '--'
+ commented = '--'
+ skip = true
+ else if commented is '/*' and (line.lastIndexOf('*/') is (line.length - 2))
+ commented = false
+ skip = true
+ else if commented is '--' and line is '--'
+ commented = false
+ skip = true
+ skip = true if line.indexOf('--') is 0
+ not commented and not skip
+ ).join('\n')
hqls = hqls.split ';'
hqls = hqls.map (query) -> query.trim()
hqls = hqls.filter (query) -> query.indexOf('--') isnt 0 and query isnt ''
View
47 test/EscapeTest.coffee
@@ -0,0 +1,47 @@
+
+assert = require 'assert'
+hive = require "#{__dirname}/.."
+config = require './config'
+
+client = hive.createClient config
+
+module.exports =
+ 'Multi # Escape': (next) ->
+ count_before = 0
+ count_row = 0
+ client.multi_query("""
+ --
+ create db
+ --
+ CREATE DATABASE IF NOT EXISTS #{config.db};
+ /*
+ create table
+ -- with some dash
+ */
+ CREATE TABLE IF NOT EXISTS #{config.table} (
+ a_bigint BIGINT,
+ an_int INT,
+ a_date STRING
+ )
+ ROW FORMAT DELIMITED
+ FIELDS TERMINATED BY ',';
+ -- load data
+ LOAD DATA LOCAL INPATH '#{__dirname}/data.csv' OVERWRITE INTO TABLE #{config.table};
+ -- return data
+ SELECT * FROM #{config.table};
+ """)
+ .on 'before', (query) ->
+ count_before++
+ .on 'row', (row) ->
+ count_row++
+ .on 'error', (err) ->
+ console.log err
+ assert.ifError err
+ .on 'end', (query) ->
+ assert.eql count_before, 4
+ assert.eql count_row, 54
+ assert.eql query, "SELECT * FROM #{config.table}"
+ next()
+ 'Close': (next) ->
+ client.end()
+ next()
View
14 test/MultiExecuteTest.coffee
@@ -1,11 +1,9 @@
assert = require 'assert'
hive = require "#{__dirname}/.."
+config = require './config'
-db = 'test_database'
-table = 'test_table'
-
-client = hive.createClient require './config.json'
+client = hive.createClient config
module.exports =
'Multi # Execute # String': (next) ->
@@ -14,9 +12,9 @@ module.exports =
count_both = 0
execute = client.multi_execute """
-- create db
- CREATE DATABASE IF NOT EXISTS #{db};
+ CREATE DATABASE IF NOT EXISTS #{config.db};
-- create table
- CREATE TABLE IF NOT EXISTS #{table} (
+ CREATE TABLE IF NOT EXISTS #{config.table} (
a_bigint BIGINT,
an_int INT,
a_date STRING
@@ -24,7 +22,7 @@ module.exports =
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',';
-- load data
- LOAD DATA LOCAL INPATH '#{__dirname}/data.csv' OVERWRITE INTO TABLE #{table};
+ LOAD DATA LOCAL INPATH '#{__dirname}/data.csv' OVERWRITE INTO TABLE #{config.table};
""", (err) ->
assert.ifError err
assert.eql count_before, 3
@@ -45,7 +43,7 @@ module.exports =
-- Throw err
Whow, that should throw an exception!;
-- create db
- CREATE DATABASE IF NOT EXISTS #{db};
+ CREATE DATABASE IF NOT EXISTS #{config.db};
""", (err) ->
assert.ok err instanceof Error
assert.eql err.name, 'HiveServerException'
View
18 test/MultiQueryTest.coffee
@@ -1,11 +1,9 @@
assert = require 'assert'
hive = require "#{__dirname}/.."
+config = require './config'
-db = 'test_database'
-table = 'test_table'
-
-client = hive.createClient require './config.json'
+client = hive.createClient config
module.exports =
'Multi # Query # String': (next) ->
@@ -13,9 +11,9 @@ module.exports =
count_row = 0
client.multi_query("""
-- create db
- CREATE DATABASE IF NOT EXISTS #{db};
+ CREATE DATABASE IF NOT EXISTS #{config.db};
-- create table
- CREATE TABLE IF NOT EXISTS #{table} (
+ CREATE TABLE IF NOT EXISTS #{config.table} (
a_bigint BIGINT,
an_int INT,
a_date STRING
@@ -23,9 +21,9 @@ module.exports =
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',';
-- load data
- LOAD DATA LOCAL INPATH '#{__dirname}/data.csv' OVERWRITE INTO TABLE #{table};
+ LOAD DATA LOCAL INPATH '#{__dirname}/data.csv' OVERWRITE INTO TABLE #{config.table};
-- return data
- SELECT * FROM #{table};
+ SELECT * FROM #{config.table};
""")
.on 'before', (query) ->
count_before++
@@ -36,7 +34,7 @@ module.exports =
.on 'end', (query) ->
assert.eql count_before, 4
assert.eql count_row, 54
- assert.eql query, "SELECT * FROM #{table}"
+ assert.eql query, "SELECT * FROM #{config.table}"
next()
'Multi # Query # Error in execute # No callback': (next) ->
count_before = 0
@@ -45,7 +43,7 @@ module.exports =
-- Throw err
Whow, that should throw an exception!;
-- create db
- CREATE DATABASE IF NOT EXISTS #{db};
+ CREATE DATABASE IF NOT EXISTS #{config.db};
""")
.on 'before', (query) ->
count_before++
View
22 test/QueryTest.coffee
@@ -1,20 +1,18 @@
assert = require 'assert'
hive = require "#{__dirname}/.."
+config = require './config'
-db = 'test_database'
-table = 'test_table'
-
-client = hive.createClient require './config.json'
+client = hive.createClient config
module.exports =
'Prepare': (next) ->
- client.execute "CREATE DATABASE IF NOT EXISTS #{db}", (err) ->
+ client.execute "CREATE DATABASE IF NOT EXISTS #{config.db}", (err) ->
assert.ifError err
- client.execute "USE #{db}", (err) ->
+ client.execute "USE #{config.db}", (err) ->
assert.ifError err
client.execute """
- CREATE TABLE IF NOT EXISTS #{table} (
+ CREATE TABLE IF NOT EXISTS #{config.table} (
a_bigint BIGINT,
an_int INT,
a_date STRING
@@ -24,14 +22,14 @@ module.exports =
""", (err) ->
assert.ifError err
client.execute """
- LOAD DATA LOCAL INPATH '#{__dirname}/data.csv' OVERWRITE INTO TABLE #{table}
+ LOAD DATA LOCAL INPATH '#{__dirname}/data.csv' OVERWRITE INTO TABLE #{config.table}
""", (err) ->
assert.ifError err
next()
'Query # all': (next) ->
count = 0
call_row_first = call_row_last = false
- client.query("SELECT * FROM #{table}")
+ client.query("SELECT * FROM #{config.table}")
.on 'row', (row, index) ->
assert.eql index, count
count++
@@ -52,7 +50,7 @@ module.exports =
next()
'Query # n': (next) ->
count = 0
- client.query("select * from #{table}", 10)
+ client.query("select * from #{config.table}", 10)
.on 'row', (row, index) ->
assert.eql index, count
count++
@@ -77,7 +75,7 @@ module.exports =
next()
'Query # pause/resume': (next) ->
count = 0
- query = client.query("select * from #{table}", 10)
+ query = client.query("select * from #{config.table}", 10)
.on 'row', (row, index) ->
assert.eql index, count
count++
@@ -95,7 +93,7 @@ module.exports =
# answer is no
count = 0
client.execute 'set hive.cli.print.header=true', (err) ->
- query = client.query("select * from #{table}", 10)
+ query = client.query("select * from #{config.table}", 10)
.on 'row', (row, index) ->
count++
.on 'error', (err) ->
View
4 test/config.json
@@ -2,5 +2,7 @@
"version": "0.7.1-cdh3u2",
"server": "127.0.0.1",
"port": 10000,
- "timeout": 1000
+ "timeout": 1000,
+ "db": "test_database",
+ "table": "test_table"
}
Please sign in to comment.
Something went wrong with that request. Please try again.