Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1265a9c

Browse files
committed
Add binary I/O capability for cube datatype.
We can adjust the not-yet-released cube--1.4--1.5.sql upgraderather than making a whole new version.KaiGai KoheiDiscussion:https://postgr.es/m/CAOP8fzZO4y60QPTK=RGDXeVeVHV9tLHKOsh7voUOoUouVCPV8A@mail.gmail.com
1 parente045565 commit1265a9c

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

‎contrib/cube/cube--1.4--1.5.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,16 @@
66
-- Remove @ and ~
77
DROPOPERATOR @ (cube, cube);
88
DROPOPERATOR ~ (cube, cube);
9+
10+
-- Add binary input/output handlers
11+
CREATEFUNCTIONcube_recv(internal)
12+
RETURNS cube
13+
AS'MODULE_PATHNAME'
14+
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
15+
16+
CREATEFUNCTIONcube_send(cube)
17+
RETURNSbytea
18+
AS'MODULE_PATHNAME'
19+
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
20+
21+
ALTERTYPE cubeSET ( RECEIVE= cube_recv, SEND= cube_send );

‎contrib/cube/cube.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include"access/gist.h"
1414
#include"access/stratnum.h"
1515
#include"cubedata.h"
16+
#include"libpq/pqformat.h"
1617
#include"utils/array.h"
1718
#include"utils/float.h"
1819

@@ -31,6 +32,8 @@ PG_FUNCTION_INFO_V1(cube_in);
3132
PG_FUNCTION_INFO_V1(cube_a_f8_f8);
3233
PG_FUNCTION_INFO_V1(cube_a_f8);
3334
PG_FUNCTION_INFO_V1(cube_out);
35+
PG_FUNCTION_INFO_V1(cube_send);
36+
PG_FUNCTION_INFO_V1(cube_recv);
3437
PG_FUNCTION_INFO_V1(cube_f8);
3538
PG_FUNCTION_INFO_V1(cube_f8_f8);
3639
PG_FUNCTION_INFO_V1(cube_c_f8);
@@ -319,6 +322,59 @@ cube_out(PG_FUNCTION_ARGS)
319322
PG_RETURN_CSTRING(buf.data);
320323
}
321324

325+
/*
326+
* cube_send - a binary output handler for cube type
327+
*/
328+
Datum
329+
cube_send(PG_FUNCTION_ARGS)
330+
{
331+
NDBOX*cube=PG_GETARG_NDBOX_P(0);
332+
StringInfoDatabuf;
333+
int32i,
334+
nitems=DIM(cube);
335+
336+
pq_begintypsend(&buf);
337+
pq_sendint32(&buf,cube->header);
338+
if (!IS_POINT(cube))
339+
nitems+=nitems;
340+
/* for symmetry with cube_recv, we don't use LL_COORD/UR_COORD here */
341+
for (i=0;i<nitems;i++)
342+
pq_sendfloat8(&buf,cube->x[i]);
343+
344+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
345+
}
346+
347+
/*
348+
* cube_recv - a binary input handler for cube type
349+
*/
350+
Datum
351+
cube_recv(PG_FUNCTION_ARGS)
352+
{
353+
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
354+
int32header;
355+
int32i,
356+
nitems;
357+
NDBOX*cube;
358+
359+
header=pq_getmsgint(buf,sizeof(int32));
360+
nitems= (header&DIM_MASK);
361+
if (nitems>CUBE_MAX_DIM)
362+
ereport(ERROR,
363+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
364+
errmsg("cube dimension is too large"),
365+
errdetail("A cube cannot have more than %d dimensions.",
366+
CUBE_MAX_DIM)));
367+
if ((header&POINT_BIT)==0)
368+
nitems+=nitems;
369+
cube=palloc(offsetof(NDBOX,x)+sizeof(double)*nitems);
370+
SET_VARSIZE(cube, offsetof(NDBOX,x)+sizeof(double)*nitems);
371+
cube->header=header;
372+
for (i=0;i<nitems;i++)
373+
cube->x[i]=pq_getmsgfloat8(buf);
374+
375+
PG_RETURN_NDBOX_P(cube);
376+
}
377+
322378

323379
/*****************************************************************************
324380
* GiST functions

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp