Skip to content

Skeleton of bottom-up FDW #530

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 3 commits 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,34 @@
/*
* Copyright (c) 2015-2022 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Chapman Flack
*/
package org.postgresql.pljava.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import java.sql.SQLData; // referred to in javadoc

/**
* Annotation on a PL/Java class that will ...
*
* Note: we need to handle wrapper, server, and table with
* correct precedence.
*
* Note: we will want method-level annotations as well.
*/
@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) @Documented
public @interface BaseFDW
{
Class<? extends Relation> relationClass();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2015-2022 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Chapman Flack
*/
package org.postgresql.pljava.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import java.sql.SQLData; // referred to in javadoc

/**
* Annotation on a PL/Java method that will ...
*
* Would this be better handled via a standardized interface?
* Or by breaking the enums apart and using logic later?...
*/
@Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) @Documented
public @interface BaseFDWMethod
{
enum Operation {
// initialization...
GET_REL_SIZE,
GET_PATHS,

// preparation and cleanup
SCAN_PLAN,
SCAN_OPEN,
SCAN_CLOSE,
SCAN_EXPLAIN,

INSERT_PLAN,
INSERT_OPEN,
INSERT_CLOSE,

MODIFY_PLAN,
MODIFY_OPEN,
MODIFY_CLOSE,
MODIFY_EXPLAIN,

DIRECT_PLAN,
DIRECT_OPEN,
DIRECT_CLOSE,
DIRECT_EXPLAIN,

GET_SCAN_BATCH_SIZE,
GET_MODIFY_BATCH_SIZE,
GET_DIRECT_BATCH_SIZE,

// actual data transfer
NEXT,
RESET,

INSERT,
INSERT_BATCH,

UPDATE,
DELETE,
TRUNCATE,

// some of the rest...
SUPPORTS_PARALLEL_SCANS,
SUPPORTS_ASYNCHRONOUS_EXECUTION,

VACUUM,
ANALYZE,

IMPORT_SCHEMA_STATEMENT,

//...
};

Operation operation();

// an alternative...
enum Step {
PLAN,
OPEN,
CLOSE,
EXPLAIN
};

enum Operation1 {
SCAN,
INSERT,
UPDATE,
DELETE
// TRUNCATE
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2015-2022 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Chapman Flack
*/
package org.postgresql.pljava.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import java.sql.SQLData; // referred to in javadoc

/**
* Annotation on a PL/Java class that will ...
*
* This assumes a Builder pattern built on top of the
* FdwValidator API.
*
* Note: we need to handle wrapper, server, and table with
* correct precedence.
*
* Note: we may not need method level annotations since we
* only need to worry about two methods and they can be
* specified here.
*/
@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) @Documented
public @interface BaseFDW
{
Class<? extends Relation> relationClass();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2015-2020 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Chapman Flack
*/
package org.postgresql.pljava.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import java.sql.SQLData; // referred to in javadoc

/**
* Annotation on a PL/Java class that will ...
*
* Note: we need to handle wrapper, server, and table with
* correct precedence.
*
* Note: we will want method-level annotations as well.
*/

@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) @Documented
public @interface MappedFDW
{
Class<? extends Relation> relationClass();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2015-2022 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Chapman Flack
*/
package org.postgresql.pljava.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import java.sql.SQLData; // referred to in javadoc

/**
* Annotation on a PL/Java class that will ...
*
* This assumes a Builder pattern built on top of the
* FdwValidator API.
*
* Note: we need to handle wrapper, server, and table with
* correct precedence.
*
* Note: we may not need method level annotations since we
* only need to worry about two methods and they can be
* specified here.
*/
@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) @Documented
public @interface BaseFDW
{
Class<? extends Relation> relationClass();
}
29 changes: 27 additions & 2 deletions pljava-so/src/main/c/Function.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ struct Function_
*/
bool isUDT;

/**
* True if this is a FDW function (open/next/reset/close/...)
*/
bool isFDW;

/**
* Java class, i.e. the UDT class or the class where the static method
* is defined.
Expand Down Expand Up @@ -163,6 +168,19 @@ struct Function_
*/
UDTFunction udtFunction;
} udt;

struct
{
/**
* The FDW that this function is associated with
*/
FDW fdw;

/**
* The UDT function to call - there are many...
*/
// FDWFunction fdwFunction;
} fdw;
} func;
};

Expand All @@ -181,7 +199,7 @@ static void _Function_finalize(PgObject func)
Function self = (Function)func;
JNI_deleteGlobalRef(self->clazz);
JNI_deleteGlobalRef(self->schemaLoader);
if(!self->isUDT)
if(!self->isUDT && !self->isFDW)
{
JNI_deleteGlobalRef(self->func.nonudt.invocable);
if(self->func.nonudt.typeMap != 0)
Expand Down Expand Up @@ -781,7 +799,7 @@ static Function Function_create(
self->func.nonudt.invocable = JNI_newGlobalRef(invocable);
JNI_deleteLocalRef(invocable);
}
else if ( ! self->isUDT )
else if ( ! self->isUDT && ! self->isFDW )
{
pfree(self);
if ( forValidator )
Expand Down Expand Up @@ -920,6 +938,11 @@ Function_invoke(
if(self->isUDT)
return self->func.udt.udtFunction(self->func.udt.udt, fcinfo);

if(self->isFDW)
{
// return self->func.fdw.fdw(self->func.fdw.fdw, fcinfo);
}

if ( self->func.nonudt.isMultiCall )
{
if ( SRF_IS_FIRSTCALL() )
Expand Down Expand Up @@ -1166,6 +1189,7 @@ JNIEXPORT jboolean JNICALL
PG_TRY();
{
self->isUDT = false;
self->isFDW = false;
self->readOnly = (JNI_TRUE == readOnly);
self->schemaLoader = JNI_newGlobalRef(schemaLoader);
self->clazz = JNI_newGlobalRef(clazz);
Expand Down Expand Up @@ -1281,6 +1305,7 @@ JNIEXPORT void JNICALL
* In that case, don't store anything needing special deallocation
* such as JNI references; Function_create will do a blind pfree only.
*/
// FIXME: isFDW?
if ( pgType->typisdefined )
{
self->isUDT = true;
Expand Down
Binary file added pljava-so/src/main/c/fdw/code.pdf
Binary file not shown.
Binary file added pljava-so/src/main/c/fdw/code.ps
Binary file not shown.
Loading