Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MODULE_big = holycorn

PG_CPPFLAGS = -g -Ivendor/mruby/include -lm
EXTENSION = holycorn
SHLIB_LINK = vendor/mruby/build/i686-pc-linux-gnu/lib/libmruby.a vendor/mruby/build/i686-pc-linux-gnu/mrbgems/mruby-redis/hiredis/libhiredis.a
SHLIB_LINK = vendor/mruby/build/host/lib/libmruby.a
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing support for mruby-redis?

OBJS = holycorn.o
DATA = holycorn--1.0.sql
PGFILEDESC = "holycorn - Ruby foreign data wrapper provider"
Expand Down
22 changes: 14 additions & 8 deletions holycorn.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mruby/array.h"
#include "mruby/proc.h"
#include "mruby/compile.h"
#include "mruby/numeric.h"
#include "mruby/string.h"
#include "mruby/range.h"
#include "mruby/hash.h"
Expand All @@ -28,7 +29,15 @@
#include "optimizer/pathnode.h"
#include "optimizer/planmain.h"
#include "optimizer/restrictinfo.h"

#if PG_VERSION_NUM < 120000
#include "optimizer/var.h"
#endif

#if PG_VERSION_NUM >= 120000
#include "optimizer/optimizer.h"
#endif

#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/builtins.h"
Expand Down Expand Up @@ -155,10 +164,10 @@ static void rbGetOptions(Oid foreigntableid, HolycornPlanState *state, List **ot

if (strcmp(def->defname, "wrapper_path") == 0) { /* Extract the wrapper_path */
state->wrapper_path = defGetString(def);
options = list_delete_cell(options, lc, prev);
options = list_delete_cell(options, lc);
} else if (strcmp(def->defname, "wrapper_class") == 0) { /* Extract the wrapper_class */
state->wrapper_class = defGetString(def);
options = list_delete_cell(options, lc, prev);
options = list_delete_cell(options, lc);
}

prev = lc;
Expand Down Expand Up @@ -327,12 +336,12 @@ static TupleTableSlot * rbIterateForeignScan(ForeignScanState *node) {
} else {
slot->tts_nvalid = RARRAY_LEN(output);

slot->tts_isempty = false;
// slot->tts_isempty = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for this commenting?

slot->tts_isnull = (bool *)palloc(sizeof(bool) * slot->tts_nvalid);
slot->tts_values = (Datum *)palloc(sizeof(Datum) * slot->tts_nvalid);

if (slot->tts_nvalid <= 0) { //TODO: the size can't be < 0 but being defensive is OK :-)
slot->tts_isempty = true;
// slot->tts_isempty = true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

} else {
Datum outputDatum;
for(int i = 0; i < slot->tts_nvalid; i++) {
Expand Down Expand Up @@ -366,7 +375,7 @@ static TupleTableSlot * rbIterateForeignScan(ForeignScanState *node) {
elog(ERROR,"MRB_TT_UNDEF not supported (yet?)");
break;
case MRB_TT_FLOAT:
outputDatum = Float8GetDatum(mrb_flo_to_fixnum(column));
outputDatum = Float8GetDatum(mrb_to_flo(exec_state->mrb_state, column));
slot->tts_isnull[i] = false;
slot->tts_values[i] = outputDatum;
break;
Expand Down Expand Up @@ -424,9 +433,6 @@ static TupleTableSlot * rbIterateForeignScan(ForeignScanState *node) {
case MRB_TT_EXCEPTION:
elog(ERROR, "MRB_TT_EXCEPTION not supported (yet?)");
break;
case MRB_TT_FILE:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What has motivated that change?

elog(ERROR, "MRB_TT_FILE not supported (yet?)");
break;
case MRB_TT_ENV:
elog(ERROR, "MRB_TT_ENV not supported (yet?)");
break;
Expand Down
36 changes: 36 additions & 0 deletions load_average.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# DROP EXTENSION holycorn CASCADE;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this to the examples directory?

# CREATE EXTENSION holycorn;
# CREATE SERVER holycorn_server FOREIGN DATA WRAPPER holycorn;
# CREATE FOREIGN TABLE holytable (load1 Float8, load2 Float8, load3 Float8)
# SERVER holycorn_server
# OPTIONS (wrapper_path '/tmp/loadavg.rb');
# /tmp/loadavg.rb
class LoadAverage
def initialize(env = {}) # env contains informations provided by Holycorn
end

def each
@enum ||= ::Enumerator.new do |row|
load_averages = []
w_output = ::IO.popen("w").read
string_values = w_output.lines.first.split(":").last.strip.split
string_values.each do |string_value|
load_averages << string_value.to_f
end

row.yield load_averages
end

@enum.next
end

def import_schema(args = {})
# Keys are:
# * local_schema: the target schema
# * server_name: name of the foreign data server in-use
# * wrapper_class: name of the current class
# * any other OPTIONS passed to IMPORT FOREIGN SCHEMA
end

self
end
2 changes: 0 additions & 2 deletions scripts/build_image

This file was deleted.

2 changes: 0 additions & 2 deletions scripts/run_tests

This file was deleted.