Skip to content
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

Work-in-Progress on PL/Java refactoring, API modernization #399

Open
wants to merge 120 commits into
base: REL1_7_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
580b25a
Easy warmup: less JNI in Invocation
jcflack Jan 23, 2022
17a3a26
These two lines considered redundant
jcflack Jan 23, 2022
9342f68
Tests for use of upper memory context
jcflack Jan 23, 2022
b2094ba
Add switchToUpperContext for non-composite SRFs
jcflack Jan 23, 2022
e441724
Use SPI in the purely nested fashion it expects
jcflack Jan 23, 2022
e380e6b
Add a nested/SPI test to SetOfRecordTest
jcflack Jan 23, 2022
2d54359
Also eliminate special SRF Invocation treatment
jcflack Jan 23, 2022
d2b920b
Merge Invocation/set-returning-function rework
jcflack Jan 23, 2022
41eb615
Two caching tools: CacheMap and SwitchPointCache
jcflack Jan 23, 2022
7655fde
Adapter and org.postgresql.pljava.adt.spi package
jcflack Jan 23, 2022
b35c65a
Package org.postgresql.pljava.adt: contracts
jcflack Jan 23, 2022
7786fbf
CharsetEncoding, CatalogObject, and a few more
jcflack Jan 23, 2022
42805b1
Add enough implementation for CharsetEncoding use
jcflack Jan 23, 2022
712f5d2
Expose MemoryContext and ResourceOwner in Java
jcflack Jan 23, 2022
5a9cdf9
Begin MemoryContext/ResourceOwner implementation
jcflack Jan 23, 2022
f387648
Fix an old PgSavepoint bug
jcflack Jan 23, 2022
169b5dc
Now an Invocation is also a Lifespan
jcflack Jan 23, 2022
f7561df
DualState clients that pass no Lifespan
jcflack Jan 23, 2022
6ba4e66
Clients using Invocation.current as Lifespan
jcflack Jan 23, 2022
901712a
Client using its own ResourceOwner as Lifespan
jcflack Jan 23, 2022
827f2d6
Client with both ResourceOwner and MemoryContext
jcflack Jan 23, 2022
349c3e8
Eliminate last use of DualState.Key
jcflack Jan 23, 2022
ea86c77
Merge MemoryContext/ResourceOwner API and uses
jcflack Jan 23, 2022
fc9bd9c
Adapt SQLXMLImpl to be creatable from Java
jcflack Jan 23, 2022
a0269b8
Build out the TupleDescriptor implementation
jcflack Jan 23, 2022
1f17675
Build out TupleTableSlot implementation
jcflack Jan 23, 2022
2e74a6b
Build out the CatalogObject implementation
jcflack Jan 23, 2022
a4656f5
RegClass and RegType have a special relationship
jcflack Jan 23, 2022
e742fae
Attribute, naturally, has complications
jcflack Jan 23, 2022
5adf2c8
Selectively invalidate RegClass and RegType
jcflack Jan 23, 2022
33530b5
Here's a simple complete one, a Database object
jcflack Jan 23, 2022
7ffea74
The rest is straight implementation
jcflack Jan 23, 2022
8ce2c87
A test jig that's been used during development
jcflack Jan 23, 2022
4a773cd
A couple straggling RegType methods
jcflack Jan 23, 2022
9a833d2
Spotted a copy-pasto in an assertion message
jcflack Jan 23, 2022
62d3694
Fix copyright years that were wrong as committed
jcflack Jan 31, 2022
4fa6a19
Pacify AppVeyor
jcflack Jan 31, 2022
f135135
Update straggling currentInvocation checks
jcflack Jan 31, 2022
0b0e4de
Missing initializer caught by MacOS clang
jcflack Jan 31, 2022
04431c4
Look for a way to confirm ARR_DIMS under clang
jcflack Jan 31, 2022
a9f24a9
Give up static check of OFFSET_ArrayType_DIMS
jcflack Jan 31, 2022
cf2f8c5
See if clang permits sizeof *ARR_DIMS(0)
jcflack Jan 31, 2022
13547a9
More work on array adapters
jcflack Feb 1, 2022
4bf4a8d
Some polishing of javadocs and code
jcflack Feb 1, 2022
8140b01
Merge REL1_7_STABLE into feature/REL1_7_STABLE/model
jcflack Jun 14, 2023
e55625e
New ACL rights appear in PG 15 and in 16
jcflack Jun 14, 2023
b0b198d
Whitespace only
jcflack Jun 14, 2023
52acfdf
Numeric typmods change in PG 15
jcflack Jun 14, 2023
acdbb2b
Fix example in AbstractType javadoc
jcflack Jul 31, 2023
101ae01
Additions to AbstractType
jcflack Jul 31, 2023
c7e9ae1
Add methods to Adapter to derive multiarrays
jcflack Jul 31, 2023
45830da
Add ArrayBuilder.build() and a suitable service
jcflack Jul 31, 2023
ff9768b
Implement the multi-array building
jcflack Jul 31, 2023
ecccd54
Consolidate the temporary test jig methods
jcflack Jul 31, 2023
1423366
Add an example for multi-array retrieval
jcflack Jul 31, 2023
87d9389
Add example of a composing Adapter
jcflack Jul 31, 2023
b1b7d13
Another composing adapter, of reference type
jcflack Jul 31, 2023
4147308
A subtlety with canFetchNull is worth mentioning
jcflack Jul 31, 2023
536e87f
Show autoboxing in Adapter composition
jcflack Aug 1, 2023
3db8e54
Tidy up that example SQL query
jcflack Aug 1, 2023
299b69f
No, canFetchNull is not that subtle after all
jcflack Aug 1, 2023
8cbc383
Example didn't demonstrate null long case
jcflack Aug 2, 2023
79a8569
Add PG_VERSION_NUM to ModelConstants
jcflack Aug 3, 2023
716eac5
Let formObjectId accept a version predicate
jcflack Aug 3, 2023
3887c05
Fix an unchecked warning in array service
jcflack Aug 12, 2023
786d546
Javadoc: typos in MultiArray, tweaks in Adapter
jcflack Aug 12, 2023
566edcb
Get rid of "throws SQLException" on tts.get
jcflack Aug 15, 2023
091d8bc
Enter TargetList and its subinterface, Projection
jcflack Aug 15, 2023
1c96e3a
Start on unwrapping ResultSet as Portal
jcflack Aug 15, 2023
4398724
Muck about with SPI class
jcflack Aug 15, 2023
6ec5627
Add more methods to Portal
jcflack Aug 15, 2023
d8bbd60
Lose temporary testmeSPI stuff
jcflack Aug 15, 2023
9d8e6b7
More notational convenience in DualState
jcflack Aug 15, 2023
d966f7b
Add TupleList to present different kinds of such
jcflack Aug 15, 2023
e299b4c
Update example
jcflack Aug 15, 2023
8a0d912
Decree: applyOver methods can throw SQLException
jcflack Aug 15, 2023
ef1f192
Deprecate old hasty TupleDescriptor methods
jcflack Aug 15, 2023
cb98c80
Add test for CatalogObject class initializations
jcflack Aug 15, 2023
10a18f8
Merge targetlist into feature/REL1_7_STABLE/model
jcflack Aug 15, 2023
630717d
Narrow visibility of CatalogObjectImpl additions
jcflack Aug 15, 2023
a0ce0ea
javadoc: a sterner note about the frankenstream
jcflack Aug 15, 2023
5cfdad8
Javadoc: clarify TupleDescriptor.rowType, intern
jcflack Aug 16, 2023
29bafab
Further tame the frankenstream
jcflack Aug 18, 2023
1fc0be2
Migrate SQLXMLImpl.Readable, VarlenaWrapper->Datum
jcflack Aug 20, 2023
c107f9a
Add a set-returning function example
jcflack Aug 24, 2023
59c0ba9
Upstream has reverted MAINTAIN privilege
jcflack Aug 24, 2023
8a88cbf
Beat down unchecked warnings from Datum migration
jcflack Aug 25, 2023
0391e18
Some more missing Adapters
jcflack Aug 26, 2023
45f965c
A reference NUMERIC -> BigDecimal implementation
jcflack Aug 26, 2023
c4b123f
Comment typos caught after pushing upstream
jcflack Aug 27, 2023
606caf0
Don't mistake SQL for Java
jcflack Aug 29, 2023
5e8fa13
Banish recent unchecked warning
jcflack Sep 8, 2023
e511a12
Allow IDX_... gaps in ModelConstants
jcflack Sep 8, 2023
dc62b4e
Regroup and renumber ModelConstants
jcflack Sep 8, 2023
d1e1db3
Pick up SIZEOF_INT via ModelConstants
jcflack Sep 8, 2023
cb71f38
Rename AttNames.andIf to alsoIf
jcflack Sep 9, 2023
3131af9
Merge branch 'REL1_7_STABLE' into feature/REL1_7_STABLE/model
jcflack Sep 19, 2023
f9acf5e
Quit using paired entry points to pass 'trusted'
jcflack Oct 9, 2023
e5dd9f8
Tidy some uses of currentInvocation->function
jcflack Oct 9, 2023
15997b5
check_function_bodies readable from Java
jcflack Oct 9, 2023
19b3c1a
Sundry fixes to CatalogObject implmementations
jcflack Oct 9, 2023
afec77d
Introduce AbstractNoSplitList
jcflack Oct 9, 2023
7faf6c9
Add Identifier.Simple.None
jcflack Oct 9, 2023
57ed135
Distinguish the polymorphic pseudotypes
jcflack Oct 9, 2023
0d65d2b
Add TupleDescImpl.synthesizeDescriptor
jcflack Oct 9, 2023
a061b4e
Interlude: BitSet <-> PostgreSQL bitmapset
jcflack Oct 9, 2023
95fcf8f
TupleTableSlotImpl.NullableDatum
jcflack Oct 9, 2023
08e2079
More invalidation: two more classes, and TupleDesc
jcflack Oct 9, 2023
1ea5bfa
Flesh out the RegProcedure.Memo idea
jcflack Oct 9, 2023
4567117
Give RegType a 'notional' TupleDescriptor
jcflack Oct 9, 2023
93b250c
Add API methods on RegProcedure and memo
jcflack Oct 9, 2023
7af5e94
Interfaces a PL/Java-based language implements
jcflack Oct 9, 2023
95d4133
Add DualState.SingleDeleteGlobalRefP
jcflack Oct 9, 2023
bcd6185
Now put the implementation under it
jcflack Oct 9, 2023
afaeb88
Add example
jcflack Oct 9, 2023
f6f9c61
Merge polyglot into feature/REL1_7_STABLE/model
jcflack Oct 9, 2023
cbfcd09
Restore pre-PG16 buildability (back to PG 13)
jcflack Oct 9, 2023
c327868
Fix added example for library-name diversity
jcflack Oct 9, 2023
75d93b2
Correct spelling of glot64
jcflack Apr 4, 2024
f072a64
Merge REL1_7_STABLE into feature/REL1_7_STABLE/model
jcflack Apr 4, 2024
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
Prev Previous commit
Next Next commit
Now put the implementation under it
STILL UNIMPLEMENTED AT THIS STAGE: anything to do with context
classloader management or access control contexts. A language's
trusted bit or name don't matter yet; the code will run with
whatever is granted to the intersection of its and PL/Java's
codebases without any Principal-based grants. Also,
Function_currentLoader, Function_currentTypeMap, and
Function_isCurrentReadOnly won't yet work when the call didn't
go through the legacy dispatcher, which may well cause errors
or crashes in attempting to use JDBC or SPI.

An internal-only field is added to ProceduralLanguageImpl's
RoutineSet as a place to memoize the implementing class instance,
and one to the PLJavaMemo as a place to memoize the Template
generated for a RegProcedure.

The Call methods context() and resultinfo() will return objects
if PostgreSQL supplied corresponding nodes, but those classes are,
so far, only stubs with no useful methods.

Call.result() is unimplemented for now and throws an exception.
A writable TupleTableSlot is still future work.

Call.isNull(boolean) works,  to determine whether the current
implementation will return null or void. For now, though, that's
unconditionally done by the dispatcher after the custom handler
returns, based on the type expected by PostgreSQL: null is
returned for any non-byValue type, to avoid an immediate crash,
and void is returned otherwise (some callers expecting void are
unexpectedly cranky if the void they get back is the null kind).
This corner of the implementation is still stopgap until writable
TupleTableSlot happens.
  • Loading branch information
jcflack committed Oct 9, 2023
commit bcd61853a8328749e96c545e22c0ba3cf0635221
103 changes: 94 additions & 9 deletions pljava-so/src/main/c/Backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,81 @@ static void registerGUCOptions(void)
#undef PLJAVA_ENABLE_DEFAULT
#undef PLJAVA_IMPLEMENTOR_FLAGS

static inline Datum internalCallHandler(PG_FUNCTION_ARGS);
extern PLJAVADLLEXPORT Datum pljavaDispatchRoutine(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(pljavaDispatchRoutine);

Datum pljavaDispatchRoutine(PG_FUNCTION_ARGS)
{
Invocation ctx;
Datum retval = 0;

/*
* Just in case it could be helpful in offering diagnostics later, hang
* on to an Oid that is known to refer to PL/Java (because it got here).
* It's cheap, and can be followed back to the right language and
* handler function entries later if needed.
*
* Note that doing this here, in a meta-language dispatcher, changes the
* meaning somewhat. No longer is this necessarily an oid for a routine in
* the familiar PL/Java language; it is the oid of a routine in some
* PL/Java-based language. It's still good for pinning down the path to our
* shared object, but is now more ambiguous as far as what pg_language entry
* it identifies. (To some extent, this has been the case for a while now
* anyway, since sqlj.alias_java_language.)
*/
pljavaOid = fcinfo->flinfo->fn_oid;

if ( IS_COMPLETE != initstage )
{
deferInit = false;
initsequencer( initstage, false);
}

Invocation_pushInvocation(&ctx);
PG_TRY();
{
retval = pljava_ModelUtils_callDispatch(fcinfo, false);
Invocation_popInvocation(false);
}
PG_CATCH();
{
Invocation_popInvocation(true);
PG_RE_THROW();
}
PG_END_TRY();
return retval;
}

extern PLJAVADLLEXPORT Datum pljavaDispatchInline(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(pljavaDispatchInline);

Datum pljavaDispatchInline(PG_FUNCTION_ARGS)
{
Invocation ctx;

if ( IS_COMPLETE != initstage )
{
deferInit = false;
initsequencer( initstage, false);
}

Invocation_pushInvocation(&ctx);
PG_TRY();
{
pljava_ModelUtils_inlineDispatch(fcinfo);
Invocation_popInvocation(false);
}
PG_CATCH();
{
Invocation_popInvocation(true);
PG_RE_THROW();
}
PG_END_TRY();

PG_RETURN_VOID();
}

static inline Datum legacyCallHandler(PG_FUNCTION_ARGS);

extern PLJAVADLLEXPORT Datum javau_call_handler(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(javau_call_handler);
Expand All @@ -1771,7 +1845,7 @@ PG_FUNCTION_INFO_V1(javau_call_handler);
*/
Datum javau_call_handler(PG_FUNCTION_ARGS)
{
return internalCallHandler(fcinfo);
return legacyCallHandler(fcinfo);
}

extern PLJAVADLLEXPORT Datum java_call_handler(PG_FUNCTION_ARGS);
Expand All @@ -1782,11 +1856,11 @@ PG_FUNCTION_INFO_V1(java_call_handler);
*/
Datum java_call_handler(PG_FUNCTION_ARGS)
{
return internalCallHandler(fcinfo);
return legacyCallHandler(fcinfo);
}

static inline Datum
internalCallHandler(PG_FUNCTION_ARGS)
legacyCallHandler(PG_FUNCTION_ARGS)
{
Invocation ctx;
Datum retval = 0;
Expand Down Expand Up @@ -1821,25 +1895,33 @@ internalCallHandler(PG_FUNCTION_ARGS)
return retval;
}

static Datum internalValidator(PG_FUNCTION_ARGS);
static Datum internalValidator(PG_FUNCTION_ARGS, bool legacy);

extern PLJAVADLLEXPORT Datum javau_validator(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(javau_validator);

Datum javau_validator(PG_FUNCTION_ARGS)
{
return internalValidator(fcinfo);
return internalValidator(fcinfo, true);
}

extern PLJAVADLLEXPORT Datum java_validator(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(java_validator);

Datum java_validator(PG_FUNCTION_ARGS)
{
return internalValidator(fcinfo);
return internalValidator(fcinfo, true);
}

static Datum internalValidator(PG_FUNCTION_ARGS)
extern PLJAVADLLEXPORT Datum pljavaDispatchValidator(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(pljavaDispatchValidator);

Datum pljavaDispatchValidator(PG_FUNCTION_ARGS)
{
return internalValidator(fcinfo, false);
}

static Datum internalValidator(PG_FUNCTION_ARGS, bool legacy)
{
Oid funcoid = PG_GETARG_OID(0);
Invocation ctx;
Expand Down Expand Up @@ -1884,7 +1966,10 @@ static Datum internalValidator(PG_FUNCTION_ARGS)
if ( InvalidOid == pljavaOid )
pljavaOid = funcoid;

Function_invoke(funcoid, false, true, check_function_bodies, NULL);
if ( legacy )
Function_invoke(funcoid, false, true, check_function_bodies, NULL);
else
pljava_ModelUtils_callDispatch(fcinfo, true);
Invocation_popInvocation(false);
}
PG_CATCH();
Expand Down
15 changes: 15 additions & 0 deletions pljava-so/src/main/c/ModelConstants.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ static int32 constants[] = {
TYPEOFFSET(NullableDatum, NullableDatum, isnull),
CONSTANTEXPR(SIZEOF_NullableDatum, sizeof (NullableDatum)),

TYPEOFFSET(FunctionCallInfoBaseData, fcinfo, fncollation),
TYPEOFFSET(FunctionCallInfoBaseData, fcinfo, isnull),
TYPEOFFSET(FunctionCallInfoBaseData, fcinfo, nargs),
TYPEOFFSET(FunctionCallInfoBaseData, fcinfo, args),



CONSTANTEXPR(OFFSET_TUPLEDESC_ATTRS, offsetof(struct TupleDescData, attrs)),
Expand Down Expand Up @@ -457,6 +462,16 @@ StaticAssertStmt(offsetof(strct,fld) - VARHDRSZ == \
CONFIRMEXPR( SIZEOF_NodeTag, sizeof (NodeTag) );
CONFIRMEXPR( SIZEOF_Oid, sizeof (Oid) );

#undef CONFIRMSIZEOF
#define CONFIRMSIZEOF(strct,tag,fld) \
StaticAssertStmt((sizeof ((strct *)0)->fld) == \
(org_postgresql_pljava_pg_ModelConstants_SIZEOF_##tag##_##fld), \
"Java/C sizeof mismatch for " #strct "." #fld)

CONFIRMSIZEOF( FunctionCallInfoBaseData, fcinfo, fncollation );
CONFIRMSIZEOF( FunctionCallInfoBaseData, fcinfo, isnull );
CONFIRMSIZEOF( FunctionCallInfoBaseData, fcinfo, nargs );

#undef CONFIRMSIZEOF
#undef CONFIRMVLOFFSET
#undef CONFIRMCONST
Expand Down
Loading