source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/shell/alias_checker_spec.rb
Ruby
mit
192
master
768
require 'spec_helper' describe AliasChecker do before(:each) do alias_file = <<-ZSHHISTORY ls='ls -G' logs='nocorrect logs' mkdir='nocorrect mkdir' ZSHHISTORY file = stub(:read => alias_file) File.stub!(:open).and_return(file) end it "is inialized with a filename" do File.stub!(:exist?).and_retu...
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/shell/binary_checker_spec.rb
Ruby
mit
192
master
321
require 'spec_helper' describe BinaryChecker do context "accepts a command" do it "knows that 'ls' _probably_ exists" do BinaryChecker.new("ls").should be_exist end it "knows that 'boooganone' _probably_ doesn't exists" do BinaryChecker.new("boooganone").should_not be_exist end end end
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/readers/history_reader_spec.rb
Ruby
mit
192
master
1,626
require 'spec_helper' describe HistoryReader do before(:each) do @clean_filename = "clean history" @clean_history = <<-CLEANHISTORY ls -l git status CLEANHISTORY File.stub(:exist?).and_return(true) end it "returns true for timestamp (oh my zsh) files" do @time_filename = "time history" @tim...
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/readers/oh_my_zsh_reader_spec.rb
Ruby
mit
192
master
1,297
require 'spec_helper' describe OhMyZshReader do before(:each) do File.stub(:exist?).and_return(true) end context "clean history" do before :each do clean_history = <<-ZSHHISTORY : 1319231772:0;ls -l : 1319231998:0;git status ZSHHISTORY if String.method_defined?(:encode) file = stub(:read ...
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/tree/word_tree_spec.rb
Ruby
mit
192
master
259
require 'spec_helper' describe WordTree do it "starts with 0 lines" do WordTree.new.line_count.should == 0 end it "allows you to add scriptlines" do wt = WordTree.new wt.add(ScriptLine.new("ls -l")) wt.line_count.should == 1 end end
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/tree/word_tree_node_spec.rb
Ruby
mit
192
master
3,553
require 'spec_helper' describe WordTreeNode do it "can be created as a root node" do WordTreeNode.new.should be_root end it "can be created with a word" do node = WordTreeNode.new("git") node.should_not be_root node.word.should == "git" end it "ugly words can be used and cleaned" do nod...
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/command/command_suggestion_spec.rb
Ruby
mit
192
master
452
require 'spec_helper' describe CommandSuggestion do before do AliasChecker.stub(:new).and_return(nil) end it "create with list of words" do cs = CommandSuggestion.new(["git", "commit", "-m"]) cs.abbreviation.should == "gcm" cs.to_s.should == "'git commit -m' => \e[0;32;49mgcm\e[0m" cs = Com...
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/command/command_suggestor_spec.rb
Ruby
mit
192
master
522
require 'spec_helper' describe CommandSuggestor do it "accepts plain lines" do cs = CommandSuggestor.new() cs.add("ls -l") end it "creates a wordtree with scriptlines" do cs = CommandSuggestor.new() cs.add("ls -l") cs.wordtree.should be_instance_of(WordTree) cs.wordtree.line_count.should...
github
paulmars/huffshell
https://github.com/paulmars/huffshell
spec/command/command_word_spec.rb
Ruby
mit
192
master
840
require 'spec_helper' describe CommandWord do it "doesn't touch a clean word" do CommandWord.clean("git").should == "git" end xit "removes upcase" do CommandWord.clean("Git").should == "git" end it "cleans command words that are options" do CommandWord.clean("-m").should == "m" end it "lea...
github
fluent/sigdump
https://github.com/fluent/sigdump
sigdump.gemspec
Ruby
apache-2.0
192
master
900
# encoding: utf-8 $:.push File.expand_path('../lib', __FILE__) require 'sigdump' Gem::Specification.new do |gem| gem.name = "sigdump" gem.description = "Setup signal handler which dumps backtrace of running threads and number of allocated objects per class. Require 'sigdump/setup', send SIGCONT, and see /tm...
github
fluent/sigdump
https://github.com/fluent/sigdump
lib/sigdump.rb
Ruby
apache-2.0
192
master
3,532
module Sigdump VERSION = "0.2.5" def self.setup(signal=ENV['SIGDUMP_SIGNAL'] || 'SIGCONT', path=ENV['SIGDUMP_PATH']) Kernel.trap(signal) do begin dump(path) rescue end end end def self.dump(path=ENV['SIGDUMP_PATH']) _open_dump_path(path) do |io| io.write "Sigdump at...
github
shlima/click_house
https://github.com/shlima/click_house
click_house.gemspec
Ruby
mit
192
master
1,336
lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'click_house/version' Gem::Specification.new do |spec| spec.name = 'click_house' spec.version = ClickHouse::VERSION spec.authors = ['Aliaksandr Shylau'] spec.email = ['alex.sh...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house.rb
Ruby
mit
192
master
1,852
# frozen_string_literal: true require 'date' require 'json' require 'csv' require 'uri' require 'logger' require 'faraday' require 'forwardable' require 'bigdecimal' require 'active_support/core_ext/time/calculations' require 'click_house/version' require 'click_house/errors' require 'click_house/response' require 'cl...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/errors.rb
Ruby
mit
192
master
235
# frozen_string_literal: true module ClickHouse Error = Class.new(StandardError) NetworkException = Class.new(Error) DbException = Class.new(Error) StatementException = Class.new(Error) SerializeError = Class.new(Error) end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/serializer.rb
Ruby
mit
192
master
276
# frozen_string_literal: true module ClickHouse module Serializer autoload :Base, 'click_house/serializer/base' autoload :JsonSerializer, 'click_house/serializer/json_serializer' autoload :JsonOjSerializer, 'click_house/serializer/json_oj_serializer' end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/util.rb
Ruby
mit
192
master
281
# frozen_string_literal: true module ClickHouse module Util autoload :Statement, 'click_house/util/statement' autoload :Pretty, 'click_house/util/pretty' module_function # wraps def array(input) input.is_a?(Array) ? input : [input] end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type.rb
Ruby
mit
192
master
1,072
# frozen_string_literal: true module ClickHouse module Type autoload :BaseType, 'click_house/type/base_type' autoload :NullableType, 'click_house/type/nullable_type' autoload :UndefinedType, 'click_house/type/undefined_type' autoload :DateType, 'click_house/type/date_type' autoload :DateTimeType,...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/connection.rb
Ruby
mit
192
master
3,332
# frozen_string_literal: true module ClickHouse class Connection include Extend::ConnectionHealthy include Extend::ConnectionDatabase include Extend::ConnectionTable include Extend::ConnectionSelective include Extend::ConnectionInserting include Extend::ConnectionAltering include Extend::...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/config.rb
Ruby
mit
192
master
2,757
# frozen_string_literal: true module ClickHouse class Config DEFAULTS = { adapter: Faraday.default_adapter, url: nil, scheme: 'http', host: 'localhost', port: '8123', logger: nil, database: nil, username: nil, password: nil, timeout: nil, open_tim...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/middleware.rb
Ruby
mit
192
master
528
# frozen_string_literal: true module ClickHouse module Middleware autoload :ResponseBase, 'click_house/middleware/response_base' autoload :SummaryMiddleware, 'click_house/middleware/summary_middleware' autoload :Logging, 'click_house/middleware/logging' autoload :ParseCsv, 'click_house/middleware/par...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/ast.rb
Ruby
mit
192
master
219
# frozen_string_literal: true module ClickHouse module Ast autoload :Statement, 'click_house/ast/statement' autoload :Ticker, 'click_house/ast/ticker' autoload :Parser, 'click_house/ast/parser' end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend.rb
Ruby
mit
192
master
789
# frozen_string_literal: true module ClickHouse module Extend autoload :TypeDefinition, 'click_house/extend/type_definition' autoload :Configurable, 'click_house/extend/configurable' autoload :Connectible, 'click_house/extend/connectible' autoload :ConnectionHealthy, 'click_house/extend/connection_he...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/response.rb
Ruby
mit
192
master
244
# frozen_string_literal: true module ClickHouse module Response autoload :Factory, 'click_house/response/factory' autoload :ResultSet, 'click_house/response/result_set' autoload :Summary, 'click_house/response/summary' end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/connection_table.rb
Ruby
mit
192
master
3,904
# frozen_string_literal: true module ClickHouse module Extend module ConnectionTable # @return [Array<String>] def tables Array(execute('SHOW TABLES FORMAT CSV').body).tap(&:flatten!) end # @return [ResultSet] def describe_table(name) Response::Factory.response(exec...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/connection_healthy.rb
Ruby
mit
192
master
275
# frozen_string_literal: true module ClickHouse module Extend module ConnectionHealthy def ping get('/ping', database: nil).success? end def replicas_status get('/replicas_status', database: nil).success? end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/configurable.rb
Ruby
mit
192
master
235
# frozen_string_literal: true module ClickHouse module Extend module Configurable def config(&block) yield(@config) if defined?(@config) && block @config ||= Config.new(&block) end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/connectible.rb
Ruby
mit
192
master
268
# frozen_string_literal: true module ClickHouse module Extend module Connectible def connection=(connection) @connection = connection end def connection @connection ||= Connection.new(config.clone) end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/connection_database.rb
Ruby
mit
192
master
1,162
# frozen_string_literal: true module ClickHouse module Extend module ConnectionDatabase # @return [Array<String>] def databases Array(execute('SHOW DATABASES FORMAT CSV', database: nil).body).tap(&:flatten!) end def create_database(name, if_not_exists: false, cluster: nil, engine...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/connection_altering.rb
Ruby
mit
192
master
3,000
# frozen_string_literal: true # rubocop:disable Metrics/ParameterLists module ClickHouse module Extend module ConnectionAltering def add_column(table, name, type, default: nil, if_not_exists: false, after: nil, cluster: nil) sql = 'ADD COLUMN %<exists>s %<name>s %<type>s %<default>s %<after>s' ...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/type_definition.rb
Ruby
mit
192
master
259
# frozen_string_literal: true module ClickHouse module Extend module TypeDefinition def types @types ||= Hash.new(Type::UndefinedType.new) end def add_type(type, klass) types[type] = klass end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/connection_inserting.rb
Ruby
mit
192
master
3,000
# frozen_string_literal: true module ClickHouse module Extend module ConnectionInserting DEFAULT_JSON_EACH_ROW_FORMAT = 'JSONEachRow' DEFAULT_JSON_COMPACT_EACH_ROW_FORMAT = 'JSONCompactEachRow' # @return [Boolean] # # == Example with a block # insert('rspec', columns: %i[name...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/connection_explaining.rb
Ruby
mit
192
master
372
# frozen_string_literal: true module ClickHouse module Extend module ConnectionExplaining EXPLAIN = 'EXPLAIN' EXPLAIN_RE = /\A(\s*#{EXPLAIN})/io.freeze # @return String def explain(sql, io: StringIO.new) res = execute("#{EXPLAIN} #{sql.gsub(EXPLAIN_RE, '')}") io.puts(res....
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/extend/connection_selective.rb
Ruby
mit
192
master
866
# frozen_string_literal: true module ClickHouse module Extend module ConnectionSelective # @return [ResultSet] def select_all(sql) response = get(body: sql, query: { default_format: 'JSON' }) Response::Factory.response(response, config) end def select_value(sql) r...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/serializer/json_oj_serializer.rb
Ruby
mit
192
master
284
# frozen_string_literal: true module ClickHouse module Serializer class JsonOjSerializer < Base def dump(data) Oj.dump(data, config.oj_dump_options) end private def on_setup require 'oj' unless defined?(Oj) end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/serializer/base.rb
Ruby
mit
192
master
568
# frozen_string_literal: true module ClickHouse module Serializer class Base attr_reader :config # @param config [Config] def initialize(config) @config = config on_setup end def dump(data) raise NotImplementedError, __method__ end # @return [S...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/util/statement.rb
Ruby
mit
192
master
221
# frozen_string_literal: true module ClickHouse module Util module Statement module_function def ensure(truthful, value, fallback = nil) truthful ? value : fallback end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/util/pretty.rb
Ruby
mit
192
master
589
# frozen_string_literal: true module ClickHouse module Util module Pretty SIZE_UNITS = %w[B KiB MiB GiB TiB Pib EiB].freeze module_function # rubocop:disable all def size(bytes) return '0B' if bytes == 0 exp = (Math.log(bytes) / Math.log(1024)).to_i exp = 6 if e...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/benchmark/casting.rb
Ruby
mit
192
master
1,192
# frozen_string_literal: true require 'bundler/setup' require 'benchmark' require 'pry' require_relative '../../click_house' ClickHouse.config.json_serializer = ClickHouse::Serializer::JsonOjSerializer ClickHouse.config.json_parser = ClickHouse::Middleware::ParseJsonOj ClickHouse.connection.drop_table('benchmark', i...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/benchmark/map_join.rb
Ruby
mit
192
master
332
# frozen_string_literal: true require 'benchmark' require 'stringio' INPUT = Array.new(5_000_000, 'foo bar') Benchmark.bm do |x| x.report('map.join') do INPUT.map(&:to_s).join("\n") end x.report('StringIO') do out = StringIO.new INPUT.each do |value| out << "#{value}\n" end out.strin...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/definition/column_set.rb
Ruby
mit
192
master
2,022
# frozen_string_literal: true module ClickHouse module Definition class ColumnSet TYPES = ClickHouse.types.each_with_object([]) do |(name, type), object| object << name.sub('%s', "'%s'") if type.ddl? end class << self # @input "DateTime('%s')" # @output "DateTime" ...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/definition/column.rb
Ruby
mit
192
master
1,279
# frozen_string_literal: true module ClickHouse module Definition class Column attr_accessor :name attr_accessor :type attr_accessor :nullable attr_accessor :low_cardinality attr_accessor :extensions attr_accessor :default attr_accessor :materialized attr_accessor ...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/middleware/raise_error.rb
Ruby
mit
192
master
650
# frozen_string_literal: true module ClickHouse module Middleware class RaiseError < Faraday::Middleware EXCEPTION_CODE_HEADER = 'x-clickhouse-exception-code' Faraday::Response.register_middleware self => self # @param env [Faraday::Env] def call(env) super rescue Faraday:...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/middleware/parse_json_oj.rb
Ruby
mit
192
master
485
# frozen_string_literal: true module ClickHouse module Middleware class ParseJsonOj < ResponseBase Faraday::Response.register_middleware self => self # @param env [Faraday::Env] def on_complete(env) return unless content_type?(env, content_type) env.body = Oj.load(env.body, co...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/middleware/logging.rb
Ruby
mit
192
master
1,673
# frozen_string_literal: true module ClickHouse module Middleware class Logging < Faraday::Middleware Faraday::Response.register_middleware self => self EMPTY = '' GET = :get attr_reader :logger, :starting def initialize(app = nil, logger:) @logger = logger super(...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/middleware/parse_json.rb
Ruby
mit
192
master
402
# frozen_string_literal: true module ClickHouse module Middleware class ParseJson < ResponseBase Faraday::Response.register_middleware self => self # @param env [Faraday::Env] def on_complete(env) return unless content_type?(env, content_type) env.body = JSON.parse(env.body, c...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/middleware/parse_csv.rb
Ruby
mit
192
master
375
# frozen_string_literal: true module ClickHouse module Middleware class ParseCsv < ResponseBase Faraday::Response.register_middleware self => self # @param env [Faraday::Env] def on_complete(env) return unless content_type?(env, content_type) env.body = env.body.strip.empty? ?...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/middleware/summary_middleware.rb
Ruby
mit
192
master
607
# frozen_string_literal: true module ClickHouse module Middleware class SummaryMiddleware < ResponseBase Faraday::Response.register_middleware self => self KEY = :summary # @param env [Faraday::Env] # @return [Response::Summary] def self.extract(env) env.custom_members.fet...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/middleware/response_base.rb
Ruby
mit
192
master
1,040
# frozen_string_literal: true module ClickHouse module Middleware class ResponseBase < Faraday::Middleware CONTENT_TYPE_HEADER = 'content-type' attr_reader :options attr_reader :content_type def initialize(app = nil, options: {}, content_type: nil, preserve_raw: false) super(app...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/response/result_set.rb
Ruby
mit
192
master
5,514
# frozen_string_literal: true module ClickHouse module Response class ResultSet extend Forwardable include Enumerable KEY_META_NAME = 'name' KEY_META_TYPE = 'type' def_delegators :to_a, :inspect, :each, :fetch, :length, :count, :size, :fir...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/response/summary.rb
Ruby
mit
192
master
2,923
# frozen_string_literal: true module ClickHouse module Response class Summary SUMMARY_HEADER = 'x-clickhouse-summary' KEY_TOTALS = 'totals' KEY_STATISTICS = 'statistics' KEY_ROWS_BEFORE_LIMIT_AT_LEAST = 'rows_before_limit_at_least' KEY_STAT_ELAPSED = 'elapsed' attr_reader :co...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/response/factory.rb
Ruby
mit
192
master
1,464
# frozen_string_literal: true module ClickHouse module Response class Factory KEY_META = 'meta' KEY_DATA = 'data' # @return [ResultSet] # @params faraday [Faraday::Response] # @params config [Config] def self.response(faraday, config) body = faraday.body # wr...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/base_type.rb
Ruby
mit
192
master
806
# frozen_string_literal: true module ClickHouse module Type class BaseType def cast(_value, *) raise NotImplementedError, __method__ end def cast_each(_value, *) raise NotImplementedError, __method__ end def serialize_each(_value, *) raise NotImplementedErr...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/nullable_type.rb
Ruby
mit
192
master
374
# frozen_string_literal: true module ClickHouse module Type class NullableType < BaseType def cast_each(value, *_argv) yield(value) unless value.nil? end def serialize_each(value, *_argv) yield(value) unless value.nil? end def container? true end ...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/fixed_string_type.rb
Ruby
mit
192
master
296
# frozen_string_literal: true module ClickHouse module Type class FixedStringType < BaseType def cast(value, _limit = nil) value.to_s end def serialize(value, limit = nil) value[0..(limit ? limit.pred : -1)] unless value.nil? end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/undefined_type.rb
Ruby
mit
192
master
220
# frozen_string_literal: true module ClickHouse module Type class UndefinedType < BaseType def cast(value, *) value end def serialize(value, *) value end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/decimal_type.rb
Ruby
mit
192
master
909
# frozen_string_literal: true module ClickHouse module Type class DecimalType < BaseType MAXIMUM = Float::DIG.next # clickhouse: # P - precision. Valid range: [ 1 : 76 ]. Determines how many decimal digits number can have (including fraction). # S - scale. Valid range: [ 0 : P ]. Determi...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/array_type.rb
Ruby
mit
192
master
361
# frozen_string_literal: true module ClickHouse module Type class ArrayType < BaseType def cast_each(value, *_argv, &block) value.map(&block) end def serialize_each(value, *_argv, &block) value.map(&block) end def container? true end def ddl? ...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/date_time64_type.rb
Ruby
mit
192
master
1,136
# frozen_string_literal: true module ClickHouse module Type class DateTime64Type < BaseType BASE_FORMAT = '%Y-%m-%d %H:%M:%S' CAST_FORMAT = "#{BASE_FORMAT}.%N" SERIALIZE_FORMATS = { 0 => BASE_FORMAT, 1 => "#{BASE_FORMAT}.%1N", 2 => "#{BASE_FORMAT}.%2N", 3 => "#{B...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/integer_type.rb
Ruby
mit
192
master
226
# frozen_string_literal: true module ClickHouse module Type class IntegerType < BaseType def cast(value) Integer(value) end def serialize(value) value.to_i end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/low_cardinality_type.rb
Ruby
mit
192
master
304
# frozen_string_literal: true module ClickHouse module Type class LowCardinalityType < BaseType def cast_each(value, *_argv) yield(value) end def serialize_each(value, *_argv) yield(value) end def container? true end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/string_type.rb
Ruby
mit
192
master
227
# frozen_string_literal: true module ClickHouse module Type class StringType < BaseType def cast(value, *) value.to_s end def serialize(value, *) value.to_s end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/boolean_type.rb
Ruby
mit
192
master
399
# frozen_string_literal: true module ClickHouse module Type class BooleanType < BaseType TRUE_VALUE = 1 FALSE_VALUE = 0 def cast(value) case value when TrueClass, FalseClass value else value.to_i == TRUE_VALUE end end def seriali...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/date_time_type.rb
Ruby
mit
192
master
396
# frozen_string_literal: true module ClickHouse module Type class DateTimeType < BaseType FORMAT = '%Y-%m-%d %H:%M:%S' def cast(value, tz = nil) if tz Time.find_zone(tz).strptime(value, FORMAT) else Time.strptime(value, FORMAT) end end def ser...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/ip_type.rb
Ruby
mit
192
master
224
# frozen_string_literal: true module ClickHouse module Type class IPType < BaseType def cast(value) IPAddr.new(value) end def serialize(value) value.to_s end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/float_type.rb
Ruby
mit
192
master
258
# frozen_string_literal: true module ClickHouse module Type class FloatType < BaseType def cast(value) Float(value) unless value.nil? end def serialize(value) value.to_f unless value.nil? end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/type/date_type.rb
Ruby
mit
192
master
276
# frozen_string_literal: true module ClickHouse module Type class DateType < BaseType FORMAT = '%Y-%m-%d' def cast(value) Date.strptime(value, FORMAT) end def serialize(value) value.strftime(FORMAT) end end end end
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/ast/statement.rb
Ruby
mit
192
master
2,227
# frozen_string_literal: true require 'stringio' module ClickHouse module Ast class Statement PLACEHOLDER_S = '%s' PLACEHOLDER_D = '%d' DIGIT_RE = /\A\d+\Z/.freeze attr_reader :name attr_accessor :caster def initialize(name: '') @buffer = '' @name = name ...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/ast/parser.rb
Ruby
mit
192
master
1,122
# frozen_string_literal: true require 'stringio' module ClickHouse module Ast class Parser OPEN = '(' CLOSED = ')' COMMA = ',' SPACE = ' ' attr_reader :input # @param input [String] def initialize(input) @input = input end # @refs https://clickhou...
github
shlima/click_house
https://github.com/shlima/click_house
lib/click_house/ast/ticker.rb
Ruby
mit
192
master
746
# frozen_string_literal: true require 'stringio' module ClickHouse module Ast class Ticker attr_reader :root, :current def initialize @current = Statement.new end def open current.name! opened.push(current) @current = Statement.new end def c...
github
shlima/click_house
https://github.com/shlima/click_house
spec/oj_helper.rb
Ruby
mit
192
master
256
# frozen_string_literal: tru RSpec.configure do |config| config.before(:each) do ClickHouse.config do |c| c.json_parser = ClickHouse::Middleware::ParseJsonOj c.json_serializer = ClickHouse::Serializer::JsonOjSerializer end end end
github
shlima/click_house
https://github.com/shlima/click_house
spec/spec_helper.rb
Ruby
mit
192
master
825
# frozen_string_literal: true $ROOT_PATH = File.expand_path('../../', __FILE__).freeze require 'bundler/setup' require 'click_house' require 'pry' Dir[File.join($ROOT_PATH, 'spec', 'support', '*.rb')].each { |f| require f } ClickHouse.config do |config| config.logger = Logger.new('log/test.log', level: Logger::DE...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/config_spec.rb
Ruby
mit
192
master
1,526
RSpec.describe ClickHouse::Config do describe '#assign' do it 'works' do expect { subject.assign(port: 33) }.to change { subject.port }.to(33) end it 'returns self' do expect(subject.assign({})).to be_a(described_class) end end describe '#initialize' do context 'when params' do ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/connection_spec.rb
Ruby
mit
192
master
359
RSpec.describe ClickHouse::Connection do context 'when basic auth' do subject do ClickHouse::Connection.new(ClickHouse.config.clone.assign( username: 'user', password: 'password' )) end it 'works' do expect { subject.tables }.to raise_error(ClickHouse::DbException, /Aut...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/util/pretty_spec.rb
Ruby
mit
192
master
439
RSpec.describe ClickHouse::Util::Pretty do describe '#size' do let(:expectation) do { 0 => '0B', 100 => '100.0B', 1456 => '1.4KiB', 1024000 * 2 => '2.0MiB', 10737418240 => '10.0GiB', 10737418240 * 1_000 => '9.8TiB', } end it 'works' do exp...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/ast/parser_spec.rb
Ruby
mit
192
master
1,928
RSpec.describe ClickHouse::Ast::Parser do let(:expectations) do { "Int" => 'Int', "DateTime('Asia/Istanbul')" => "DateTime('Asia/Istanbul')", "Array(Int, String(2))" => "Array(Int,String(2))", "Array(Array(Array(Array(Nullable(Int, String)))))" => "Array(Array(Array(Array(Nullable(Int,Stri...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/enum_spec.rb
Ruby
mit
192
master
981
# frozen_string_literal: true RSpec.describe 'Enum' do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a Enum('foo' = 1, 'bar' = 2), b Nullable(Enum('foo' = 1, 'bar' = 2)) ) ENGINE Memory SQL end describe 'cast' do bef...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/table_schema_spec.rb
Ruby
mit
192
master
1,653
RSpec.describe ClickHouse::Response::ResultSet do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a Boolean, b Array(Nullable(String)) ) ENGINE Memory SQL end let(:schema) do subject.table_schema('rspec') end des...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/tuple_spec.rb
Ruby
mit
192
master
1,121
# frozen_string_literal: true RSpec.describe ClickHouse::Type::TupleType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a Tuple(IPv4, Nullable(Date), Nullable(String)) ) ENGINE Memory SQL end describe 'cast' do before do ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/date_time64_spec.rb
Ruby
mit
192
master
1,819
RSpec.describe ClickHouse::Type::DateTime64Type do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a DateTime64(0), b DateTime64(9, 'Europe/Kyiv'), c Nullable(DateTime64(9)), d Nullable(DateTime64(9, 'Europe/Kyiv')), ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/float_spec.rb
Ruby
mit
192
master
1,145
# frozen_string_literal: true RSpec.describe ClickHouse::Type::FloatType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a Float32, b Float64, c Nullable(Float64) ) ENGINE Memory SQL end describe 'ca...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/decimal_spec.rb
Ruby
mit
192
master
1,863
RSpec.describe ClickHouse::Type::DecimalType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a Decimal(10,10), b Decimal32(1), c Decimal64(10), d Decimal128(20), e Nullable(Decimal256(30)) ) ENGINE...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/ip_spec.rb
Ruby
mit
192
master
1,410
# frozen_string_literal: true RSpec.describe ClickHouse::Type::IPType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a IPv4, b Nullable(IPv4), c IPv6, d Nullable(IPv6) ) ENGINE Memory SQL end desc...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/formats.rb
Ruby
mit
192
master
1,168
# frozen_string_literal: true RSpec.describe ClickHouse::Extend::ConnectionSelective do subject do ClickHouse.connection end context 'when RowBinary' do let(:query) do 'SELECT 1 FORMAT RowBinary' end it '#select_one' do got = subject.select_one(query) expect(got).to eq("\u0001...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/function_spec.rb
Ruby
mit
192
master
419
RSpec.describe 'Functions' do subject do ClickHouse.connection end let(:expectations) do { 'select NOW()' => Time, 'select 1 + 1' => Integer, 'select 1 * 1.0' => Float, 'select empty([])' => Integer, 'select 1 > 0' => Integer, } end it 'works' do expectations.e...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/integer_spec.rb
Ruby
mit
192
master
1,970
# frozen_string_literal: true RSpec.describe ClickHouse::Type::IntegerType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a UInt8, b UInt16, c UInt32, d UInt64, e Int8, f Int16, g I...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/map_spec.rb
Ruby
mit
192
master
1,215
# frozen_string_literal: true RSpec.describe ClickHouse::Type::MapType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a Map(LowCardinality(String), Array(DateTime('Europe/Kyiv'))), b Map(Int8, IPv4) ) ENGINE Memory SQL ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/string_spec.rb
Ruby
mit
192
master
1,401
# frozen_string_literal: true RSpec.describe ClickHouse::Type::StringType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a String, b FixedString(2), c UUID, d Nullable(UUID) ) ENGINE Memory SQL end ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/symbolize_keys_spec.rb
Ruby
mit
192
master
1,133
# frozen_string_literal: true RSpec.describe ClickHouse::Config do subject do ClickHouse::Connection.new(ClickHouse.config.clone.assign(symbolize_keys: true)) end before do subject.execute <<~SQL CREATE TABLE rspec( a String, ) ENGINE Memory SQL end describe 'cast' do ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/nested_spec.rb
Ruby
mit
192
master
906
# frozen_string_literal: true RSpec.describe 'Nested' do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( json Nested( a Date ) ) ENGINE Memory SQL end describe 'cast' do before do subject.execute <<~SQL ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/boolean_type_spec.rb
Ruby
mit
192
master
1,451
# frozen_string_literal: true RSpec.describe ClickHouse::Type::BooleanType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a Boolean, b Boolean, c Boolean, d Boolean, e Nullable(Boolean) ) ENGINE ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/loggin_spec.rb
Ruby
mit
192
master
828
RSpec.describe ClickHouse::Middleware::Logging do subject do ClickHouse::Connection.new(ClickHouse.config.clone.assign(logger: logger)) end let(:out) do StringIO.new end let(:logger) do Logger.new(out) end context 'when POST' do it 'works' do subject.execute('SELECT 1') expe...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/low_cardinality_spec.rb
Ruby
mit
192
master
1,348
RSpec.describe ClickHouse::Type::LowCardinalityType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a LowCardinality(DateTime), b LowCardinality(DateTime('Europe/Kyiv')), c LowCardinality(Nullable(String)) ) ENGINE Me...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/date_spec.rb
Ruby
mit
192
master
1,017
# frozen_string_literal: true RSpec.describe ClickHouse::Type::IPType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a Date, b Nullable(Date) ) ENGINE Memory SQL end describe 'cast' do before do subject.exe...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/date_time_spec.rb
Ruby
mit
192
master
1,782
RSpec.describe ClickHouse::Type::DateTimeType do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec( a DateTime, b DateTime('Europe/Kyiv'), c Nullable(DateTime), d Nullable(DateTime('Europe/Kyiv')), e Nullable(D...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/integration/array_spec.rb
Ruby
mit
192
master
3,979
RSpec.describe ClickHouse::Type::ArrayType do subject do ClickHouse.connection end describe 'cast' do context 'many flat' do before do subject.execute <<~SQL CREATE TABLE rspec( a Array(DateTime), b Array(Nullable(DateTime)), c Array(DateT...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/extend/connection_inserting_spec.rb
Ruby
mit
192
master
3,447
# ⚠️ INSERT IN TESTS SHOULD HAVE A DIFFERENT ORDER OF COLUMNS # FROM THE ORDER IN THE TABLE ITSELF RSpec.describe ClickHouse::Extend::ConnectionInserting do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec(id Int64, name Nullable(String)) ENGINE Memory ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/extend/connection_explaining_spec.rb
Ruby
mit
192
master
995
RSpec.describe ClickHouse::Extend::ConnectionExplaining do subject do ClickHouse.connection end before do subject.execute <<~SQL CREATE TABLE rspec(id Int64) ENGINE TinyLog SQL end let(:expectation) do <<~TXT Expression ((Projection + Before ORDER BY)) Join (JOIN FillRigh...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/extend/connection_database_spec.rb
Ruby
mit
192
master
1,268
RSpec.describe ClickHouse::Extend::ConnectionDatabase do subject do ClickHouse.connection end describe '#databases' do it 'works' do expect(subject.databases).to include('default', 'system', ClickHouse.config.database) end end describe '#create_database' do context 'when exists' do ...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/extend/connection_table_spec.rb
Ruby
mit
192
master
8,289
RSpec.describe ClickHouse::Extend::ConnectionTable do subject do ClickHouse.connection end describe '#tables' do context 'when empty' do it 'works' do expect(subject.tables).to eq([]) end end context 'when exists' do before do subject.execute <<~SQL CR...
github
shlima/click_house
https://github.com/shlima/click_house
spec/click_house/extend/connection_selective_spec.rb
Ruby
mit
192
master
1,667
RSpec.describe ClickHouse::Extend::ConnectionSelective do subject do ClickHouse.connection end describe '#select_value' do context 'when exists' do it 'works' do expect(subject.select_value('SELECT 13')).to eq(13) end end context 'when not exists' do it 'works' do ...