Skip to content

Prototype based on blackhole_fdw and c -> java calls #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.postgresql.pljava.fdw;

public interface FDWForeignDataWrapper {
FDWServer getServer();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.postgresql.pljava.fdw;

public interface FDWForeignTable {
FDWPlanState newPlanState();
FDWScanState ScanState();

default boolean updatable() { return false; }

default void analyze() { };
//
// default void vacuum() { };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.postgresql.pljava.fdw;

public interface FDWPlanState {
void open();

void close();

// int rows();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.postgresql.pljava.fdw;

public interface FDWScanState {
void open();
void next(Object slot);
void reset();
void close();

// void explain(); ??
}
10 changes: 10 additions & 0 deletions pljava-api/src/main/java/org/postgresql/pljava/fdw/FDWServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.postgresql.pljava.fdw;

import java.sql.ResultSetMetaData;

public interface FDWServer {
FDWForeignTable getForeignTable();

// For 'importSchemaStmt()
ResultSetMetaData getMetaData();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.postgresql.pljava.fdw;

public interface FDWValidator {
void addOption(int relid, String key, String value);

boolean validate();

FDWForeignDataWrapper getForeignDataWrapper();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.postgresql.pljava.example.fdw;

import org.postgresql.pljava.fdw.FDWForeignDataWrapper;
import org.postgresql.pljava.fdw.FDWServer;

import java.util.Collections;
import java.util.Map;
import java.util.logging.Logger;

/**
* A ForeignDataWrapper. (Persistent)
*
* Note: a single ForeignDataWrapper may contain multiple servers
* so there should be caching somewhere.
*/
public class BlackholeForeignDataWrapper implements FDWForeignDataWrapper {
private static final Logger LOG = Logger.getLogger(BlackholeForeignDataWrapper.class.getName());

public BlackholeForeignDataWrapper() {
this(Collections.emptyMap());
}

public BlackholeForeignDataWrapper(Map<String, String> options) {
LOG.info("constructor");
}

@Override
public FDWServer getServer() {
LOG.info("getServer()");
return new BlackholeServer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.postgresql.pljava.example.fdw;

import org.postgresql.pljava.fdw.FDWForeignDataWrapper;
import org.postgresql.pljava.fdw.FDWPlanState;
import org.postgresql.pljava.fdw.FDWScanState;
import org.postgresql.pljava.fdw.FDWForeignTable;

import java.util.Collections;
import java.util.Map;
import java.util.logging.Logger;

/**
* A Foreign Table (persistent)
*
* A single ForeignTable may have multiple PlanStates and ScanStates
* however they are transient and unlikely to be reused.
*/
public class BlackholeForeignTable implements FDWForeignTable {
private static final Logger LOG = Logger.getLogger(BlackholeForeignTable.class.getName());

public BlackholeForeignTable() {
this(Collections.emptyMap());
}

public BlackholeForeignTable(Map<String, String> options) {
LOG.info("constructor");
}

@Override
public FDWPlanState newPlanState() {
LOG.info("getPlanState()");
return new BlackholePlanState(this);
}

@Override
public FDWScanState newScanState() {
LOG.info("newScanState()");
return new BlackholeScanState(this);
}

@Override
public boolean updatable() {
LOG.info("updatable()");
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.postgresql.pljava.example.fdw;

import org.postgresql.pljava.fdw.FDWPlanState;

import java.util.logging.Logger;

/**
* A ForeignTable plan state. (Temporary)
*/
public class BlackholePlanState implements FDWPlanState {
private static final Logger LOG = Logger.getLogger(BlackholePlanState.class.getName());

private final BlackholeForeignTable table;

public BlackholePlanState(BlackholeForeignTable table) {
LOG.info("constructor()");
this.table = table;
}

@Override
public void open() {
LOG.info("open()");
}

@Override
public void close() {
LOG.info("close()");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.postgresql.pljava.example.fdw;

import org.postgresql.pljava.fdw.FDWScanState;

import java.util.logging.Logger;

/**
* A ForeignTable scan state. (Temporary)
*/
public class BlackholeScanState implements FDWScanState {
private static final Logger LOG = Logger.getLogger(BlackholeScanState.class.getName());

private final BlackholeForeignTable table;

public BlackholeScanState(BlackholeForeignTable table) {
LOG.info("constructor()");
this.table = table;
}

@Override
public void open() {
LOG.info("open()");
}

@Override
public void next(Object slot) {
LOG.info("next()");
}

@Override
public void reset() {
LOG.info("reset()");
}

@Override
public void close() {
LOG.info("close()");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.postgresql.pljava.example.fdw;

import org.postgresql.pljava.fdw.FDWForeignTable;
import org.postgresql.pljava.fdw.FDWServer;

import java.sql.ResultSetMetaData;
import java.util.Collections;
import java.util.Map;
import java.util.logging.Logger;

/**
* A Foreign Server (persistent)
*
* Note: a single Server may contain multiple ForeignTables
* so there should be caching somewhere.
*/
public class BlackholeServer implements FDWServer {
private static final Logger LOG = Logger.getLogger(BlackholeServer.class.getName());

public BlackholeServer() {
this(Collections.emptyMap());
}

public BlackholeServer(Map<String, String> options) {
LOG.info("constructor()");
}

@Override
public FDWForeignTable getForeignTable() {
LOG.info("getForeignTable()");
return new BlackholeForeignTable() {};
}

@Override
public ResultSetMetaData getMetaData() {
LOG.info("getMetaData()");
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.postgresql.pljava.example.fdw;

import org.postgresql.pljava.fdw.FDWForeignDataWrapper;
import org.postgresql.pljava.fdw.FDWValidator;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

public class BlackholeValidator implements FDWValidator {
private static final Logger LOG = Logger.getLogger(BlackholeValidator.class.getName());

// note: we know there's only five possible integer values.
private final Map<Integer, Map<String, String>> options = new HashMap<>();

public BlackholeValidator() {
this(Collections.emptyMap());
}

public BlackholeValidator(Map<String, String> options) {
LOG.info("constructor");
}

@Override
public void addOption(int relid, String key, String value) {
LOG.info(String.format("addOption(%d, %s, %s)", relid, key, value));

if (!options.containsKey(relid)) {
options.put(relid, new HashMap<>());
}

options.get(relid).put(key, value);
}

@Override
public boolean validate() {
LOG.info("validate()");
return true;
}

@Override
public FDWForeignDataWrapper getForeignDataWrapper() {
LOG.info("getForeignDataWrapper()");
return new BlackholeForeignDataWrapper();
}
}
27 changes: 27 additions & 0 deletions pljava-so/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# TODO: pull various VERS from the environment...

FROM postgres:17.2-bookworm
LABEL authors="Bear Giles <bgiles@coyotesong.com>"

ENV TARGET=target
ENV RESOURCES=src/main/resources

# can/should be set as build property...
ENV PG_VERS=17
ENV LIBDIR=/usr/lib/postgresql/${PG_VERS}/lib
ENV EXTDIR=/usr/share/postgresql/${PG_VERS}/extension

ENV SO_NAME=pljava.so

ENV FDW_NAME=blackhole_fdw
ENV FDW_VERS=1.9.6

# this will install the standard version. It can be updated once the docker image is running in a test environment.
RUN apt-get update && apt-get install -y postgresql-${PG_VERS}-pljava postgresql-${PG_VERS}-pljava-dbgsym

COPY ${TARGET}/${SO_NAME}.so ${LIBDIR}/${SO_NAME}.so

COPY ${RESOURCES}/fdw/${FDW_NAME}.control ${EXTDIR}/
COPY ${RESOURCES}/fdw/sql/${FDW_NAME}*.sql ${EXTDIR}/

# ENTRYPOINT ["top", "-b"]
17 changes: 17 additions & 0 deletions pljava-so/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
postgresql:
image: blackhole:latest
container_name: blackhole
ports:
- '5432:5432'
environment:
POSTGRES_PASSWORD: password
networks:
- frontend

networks:
frontend:
# Specify driver options
driver: bridge
driver_opts:
com.docker.network.bridge.host_binding_ipv4: "127.0.1.1"
Loading