Class: Rgviz::MemoryExecutor::EvalSelectVisitor

Inherits:
Visitor
  • Object
show all
Defined in:
lib/rgviz/memory_executor.rb

Direct Known Subclasses

EvalGroupVisitor, EvalWhereVisitor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types_to_indices, row, row_i, rows_length, ag) ⇒ EvalSelectVisitor

Returns a new instance of EvalSelectVisitor.



381
382
383
384
385
386
387
388
389
# File 'lib/rgviz/memory_executor.rb', line 381

def initialize(types_to_indices, row, row_i, rows_length, ag)
  @types_to_indices = types_to_indices
  @row = row
  @row_i = row_i
  @rows_length = rows_length
  @row_i = row_i
  @rows_length = rows_length
  @ag = ag
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



379
380
381
# File 'lib/rgviz/memory_executor.rb', line 379

def value
  @value
end

Instance Method Details

#visit_aggregate_column(col) ⇒ Object



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/rgviz/memory_executor.rb', line 486

def visit_aggregate_column(col)
  case col.function
  when AggregateColumn::Sum
    col.argument.accept self
    @value += @ag || 0
  when AggregateColumn::Avg
    col.argument.accept self
    @value += @ag || 0
    @value = @value / @rows_length.to_f if @row_i == @rows_length - 1
  when AggregateColumn::Count
    @value = (@ag || 0) + 1
  when AggregateColumn::Max
    col.argument.accept self
    @value = @ag if @ag && @ag > @value
  when AggregateColumn::Min
    col.argument.accept self
    @value = @ag if @ag && @ag < @value
  end
  false
end

#visit_boolean_column(col) ⇒ Object



405
406
407
# File 'lib/rgviz/memory_executor.rb', line 405

def visit_boolean_column(col)
  @value = col.value
end

#visit_date_column(col) ⇒ Object



409
410
411
# File 'lib/rgviz/memory_executor.rb', line 409

def visit_date_column(col)
  @value = col.value
end

#visit_date_time_column(node) ⇒ Object



413
414
415
# File 'lib/rgviz/memory_executor.rb', line 413

def visit_date_time_column(node)
  @value = node.value
end

#visit_id_column(col) ⇒ Object



391
392
393
394
395
# File 'lib/rgviz/memory_executor.rb', line 391

def visit_id_column(col)
  i = @types_to_indices[col.name]
  raise "Unknown column #{col}" unless i
  @value = @row[i]
end

#visit_number_column(col) ⇒ Object



397
398
399
# File 'lib/rgviz/memory_executor.rb', line 397

def visit_number_column(col)
  @value = col.value
end

#visit_scalar_function_column(node) ⇒ Object



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/rgviz/memory_executor.rb', line 421

def visit_scalar_function_column(node)
  if node.arguments.length >= 1
    node.arguments[0].accept self; val1 = @value
  end
  if node.arguments.length == 2
    node.arguments[1].accept self; val2 = @value
  end
  case node.function
  when ScalarFunctionColumn::Sum
    @value = val1 + val2
  when ScalarFunctionColumn::Difference
    @value = val1 - val2
  when ScalarFunctionColumn::Product
    @value = val1 * val2
  when ScalarFunctionColumn::Quotient
    @value = val1 / val2
  when ScalarFunctionColumn::Concat
    @value = "#{val1}#{val2}"
  when ScalarFunctionColumn::DateDiff
    @value = (val1 - val2).to_i
  when ScalarFunctionColumn::Year
    @value = val1.year
  when ScalarFunctionColumn::Month
    @value = val1.month
  when ScalarFunctionColumn::Day
    @value = val1.day
  when ScalarFunctionColumn::DayOfWeek
    @value = val1.wday
  when ScalarFunctionColumn::Hour
    @value = val1.hour
  when ScalarFunctionColumn::Minute
    @value = val1.min
  when ScalarFunctionColumn::Second
    @value = val1.sec
  when ScalarFunctionColumn::Quarter
    @value = (val1.month / 3.0).ceil
  when ScalarFunctionColumn::Round
    @value = val1.round
  when ScalarFunctionColumn::Floor
    @value = val1.floor
  when ScalarFunctionColumn::Millisecond
    raise "Millisecond is not implemented"
  when ScalarFunctionColumn::Lower
    @value = val1.downcase
  when ScalarFunctionColumn::Upper
    @value = val1.upcase
  when ScalarFunctionColumn::Now
    @value = Time.now
  when ScalarFunctionColumn::ToDate
    case @value
    when Date
      @value = @value
    when Time
      @value = Date.civil @value.year, @value.month, @value.day
    when Integer
      seconds = @value / 1000
      millis = @value % 1000
      @value = Time.utc 1970, 1, 1, 0, 0, 0
      @value += seconds + millis / 1000.0
      @value = Date.civil @value.year, @value.month, @value.day
    end
  end
  false
end

#visit_string_column(col) ⇒ Object



401
402
403
# File 'lib/rgviz/memory_executor.rb', line 401

def visit_string_column(col)
  @value = col.value
end

#visit_time_of_day_column(node) ⇒ Object



417
418
419
# File 'lib/rgviz/memory_executor.rb', line 417

def visit_time_of_day_column(node)
  @value = node.value.strftime("%H:%M:%S")
end