Class: AmazonAthena::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/amazon_athena/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(key: nil, secret: nil, region: "us-east-1", s3_staging_dir: nil) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
# File 'lib/amazon_athena/client.rb', line 12

def initialize(key: nil, secret: nil, region: "us-east-1", s3_staging_dir: nil)
  @key = key || ENV["AWS_ACCESS_KEY"]
  @secret = secret || ENV['AWS_SECRET_KEY']
  @region = region
  @s3_staging_dir = s3_staging_dir || ENV["ATHENA_S3_STAGING_DIR"]
end

Instance Method Details

#connectionObject



97
98
99
100
101
102
103
104
105
106
# File 'lib/amazon_athena/client.rb', line 97

def connection
  return @connection if defined?(@connection) && !@connection.closed?

  @connection = JDBCHelper::Athena.connect(
    key: @key,
    secret: @secret,
    region: @region,
    s3_staging_dir: @s3_staging_dir
  )
end

#database_create(name:, location: nil, comment: nil, properties: {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/amazon_athena/client.rb', line 31

def database_create(name:, location: nil, comment: nil, properties: {})
  cmd = AmazonAthena::Commands::CreateDatabase.new(
    name: name,
    location: location,
    comment: comment,
    properties: properties
  )

  run(cmd)
end

#database_drop(database) ⇒ Object



25
26
27
28
29
# File 'lib/amazon_athena/client.rb', line 25

def database_drop(database)
  cmd = AmazonAthena::Commands::DropDatabase.new(database)

  run(cmd)
end

#databasesObject



19
20
21
22
23
# File 'lib/amazon_athena/client.rb', line 19

def databases
  cmd = AmazonAthena::Commands::ShowDatabases.new

  run(cmd)
end

#partitions(table) ⇒ Object



85
86
87
88
89
# File 'lib/amazon_athena/client.rb', line 85

def partitions(table)
  cmd = AmazonAthena::Commands::ShowPartitions.new(database_table)

  run(cmd)
end

#partitions_drop(database_table, partitions_expression) ⇒ Object



91
92
93
94
95
# File 'lib/amazon_athena/client.rb', line 91

def partitions_drop(database_table, partitions_expression)
  cmd = AmazonAthena::Commands::DropPartition.new(database_table, partitions)

  run(cmd)
end

#run(cmd, preview = false) ⇒ Object



108
109
110
111
112
# File 'lib/amazon_athena/client.rb', line 108

def run(cmd, preview = false)
  return cmd.preview if preview

  cmd.run(connection)
end

#table_columns(database_table) ⇒ Object



54
55
56
57
58
# File 'lib/amazon_athena/client.rb', line 54

def table_columns(database_table)
  cmd = AmazonAthena::Commands::ShowColumns.new(database_table)

  run(cmd)
end

#table_describe(database_table) ⇒ Object



66
67
68
69
70
# File 'lib/amazon_athena/client.rb', line 66

def table_describe(database_table)
  cmd = AmazonAthena::Commands::DescribeTable.new(database_table)

  run(cmd)
end

#table_drop(database_table) ⇒ Object



48
49
50
51
52
# File 'lib/amazon_athena/client.rb', line 48

def table_drop(database_table)
  cmd = AmazonAthena::Commands::DropTable.new(database)

  run(cmd)
end

#table_properties(database_table) ⇒ Object



79
80
81
82
83
# File 'lib/amazon_athena/client.rb', line 79

def table_properties(database_table)
  cmd = AmazonAthena::Commands::ShowTableProperties.new(database_table)

  run(cmd)
end

#table_repair(database_table) ⇒ Object



72
73
74
75
76
77
# File 'lib/amazon_athena/client.rb', line 72

def table_repair(database_table)
  cmd = AmazonAthena::Commands::RepairTable.new(database_table)
  run(cmd)

  partitions(database_table)
end

#table_show_create(database_table) ⇒ Object



60
61
62
63
64
# File 'lib/amazon_athena/client.rb', line 60

def table_show_create(database_table)
  cmd = AmazonAthena::Commands::ShowCreateTable.new(database_table)

  run(cmd)
end

#tables(database) ⇒ Object



42
43
44
45
46
# File 'lib/amazon_athena/client.rb', line 42

def tables(database)
  cmd = AmazonAthena::Commands::ShowTables.new(database)

  run(cmd)
end