Skip to content

Commit

Permalink
Transform support
Browse files Browse the repository at this point in the history
Add support for TRANSFORM command.
  • Loading branch information
Euler Taveira committed Nov 23, 2019
1 parent bb4ad16 commit b31ddfa
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ add_executable(pgquarrel
src/table.h
src/textsearch.c
src/textsearch.h
src/transform.c
src/transform.h
src/trigger.c
src/trigger.h
src/type.c
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Features
</tr>
<tr>
<td>TRANSFORM</td>
<td>not implemented</td>
<td>complete</td>
<td></td>
</tr>
<tr>
Expand Down Expand Up @@ -330,6 +330,7 @@ The following command-line options are provided (all are optional):
* `subscription`: subscription comparison (default: false).
* `table`: table comparison (default: true).
* `text-search`: text search comparison (default: false).
* `transform`: transform comparison (default: false).
* `trigger`: trigger comparison (default: true).
* `type`: type comparison (default: true).
* `view`: view comparison (default: true).
Expand Down Expand Up @@ -374,6 +375,7 @@ statistics = false
subscription = false
table = true
text-search = false
transform = false
trigger = true
type = true
view = true
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef struct QuarrelGeneralOptions
bool subscription;
bool table;
bool textsearch;
bool transform;
bool trigger;
bool type;
bool view;
Expand Down
103 changes: 101 additions & 2 deletions src/quarrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* server: complete
* subscription: partial
* table: partial
* transform: complete
* trigger: partial
* type: partial
* text search configuration: partial
Expand All @@ -45,7 +46,6 @@
*
* UNSUPPORTED
* ~~~~~~~~~~~~~
* transform
*
* UNCERTAIN
* ~~~~~~~~~~~~~
Expand Down Expand Up @@ -88,6 +88,7 @@
#include "subscription.h"
#include "table.h"
#include "textsearch.h"
#include "transform.h"
#include "trigger.h"
#include "type.h"
#include "usermapping.h"
Expand All @@ -111,7 +112,8 @@ PQLStatistic qstat = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
};

FILE *fout; /* output file */
Expand Down Expand Up @@ -163,6 +165,7 @@ static void quarrelTextSearchConfigs();
static void quarrelTextSearchDicts();
static void quarrelTextSearchParsers();
static void quarrelTextSearchTemplates();
static void quarrelTransforms();
static void quarrelTriggers();
static void quarrelBaseTypes();
static void quarrelCompositeTypes();
Expand Down Expand Up @@ -282,6 +285,8 @@ help(void)
(opts.general.table) ? "true" : "false");
printf(" --text-search=BOOL text search (default: %s)\n",
(opts.general.textsearch) ? "true" : "false");
printf(" --transform=BOOL transform (default: %s)\n",
(opts.general.transform) ? "true" : "false");
printf(" --trigger=BOOL trigger (default: %s)\n",
(opts.general.trigger) ? "true" : "false");
printf(" --type=BOOL type (default: %s)\n",
Expand Down Expand Up @@ -352,6 +357,7 @@ loadConfig(const char *cf, QuarrelOptions *options)
options->general.subscription = false; /* general - subscription */
options->general.table = true; /* general - table */
options->general.textsearch = false; /* general - text-search */
options->general.transform = false; /* general - transform */
options->general.trigger = true; /* general - trigger */
options->general.type = true; /* general - type */
options->general.view = true; /* general - view */
Expand Down Expand Up @@ -576,6 +582,10 @@ loadConfig(const char *cf, QuarrelOptions *options)
mini_file_get_value(config,
"general", "text-search"));

if (mini_file_get_value(config, "general", "transform") != NULL)
options->general.transform = parseBoolean("transform", mini_file_get_value(config,
"general", "transform"));

if (mini_file_get_value(config, "general", "trigger") != NULL)
options->general.trigger = parseBoolean("trigger", mini_file_get_value(config,
"general", "trigger"));
Expand Down Expand Up @@ -3666,6 +3676,86 @@ quarrelTextSearchTemplates()
freeTextSearchTemplates(tstemplates2, ntstemplates2);
}

static void
quarrelTransforms()
{
PQLTransform *transforms1 = NULL; /* target */
PQLTransform *transforms2 = NULL; /* source */
int ntransforms1 = 0; /* # of transforms */
int ntransforms2 = 0;
int i, j;

transforms1 = getTransforms(conn1, &ntransforms1);
transforms2 = getTransforms(conn2, &ntransforms2);

for (i = 0; i < ntransforms1; i++)
logNoise("server1: transform for %s.%s language %s", transforms1[i].trftype.schemaname, transforms1[i].trftype.objectname, transforms1[i].languagename);

for (i = 0; i < ntransforms2; i++)
logNoise("server2: transform for %s.%s language %s", transforms2[i].trftype.schemaname, transforms2[i].trftype.objectname, transforms2[i].languagename);

/*
* We have two sorted lists. Let's figure out which elements are not in the
* other list.
* We have two sorted lists. The strategy is transverse both lists only once
* to figure out transforms not presented in the other list.
*/
i = j = 0;
while (i < ntransforms1 || j < ntransforms2)
{
/* End of transforms1 list. Print transforms2 list until its end. */
if (i == ntransforms1)
{
logDebug("transform for %s.%s language %s: server2", transforms2[i].trftype.schemaname, transforms2[i].trftype.objectname, transforms2[i].languagename);

dumpCreateTransform(fpre, &transforms2[j]);

j++;
qstat.transformadded++;
}
/* End of transforms2 list. Print transforms1 list until its end. */
else if (j == ntransforms2)
{
logDebug("transform for %s.%s language %s: server1", transforms1[i].trftype.schemaname, transforms1[i].trftype.objectname, transforms1[i].languagename);

dumpDropTransform(fpost, &transforms1[i]);

i++;
qstat.transformremoved++;
}
else if (compareNamesAndRelations(&transforms1[i].trftype, &transforms2[j].trftype, transforms1[i].languagename, transforms2[j].languagename) == 0)
{
logDebug("transform for %s.%s language %s: server1 server2", transforms1[i].trftype.schemaname, transforms1[i].trftype.objectname, transforms1[i].languagename);

dumpAlterTransform(fpre, &transforms1[i], &transforms2[j]);

i++;
j++;
}
else if (compareNamesAndRelations(&transforms1[i].trftype, &transforms2[j].trftype, transforms1[i].languagename, transforms2[j].languagename) < 0)
{
logDebug("transform for %s.%s language %s: server1", transforms1[i].trftype.schemaname, transforms1[i].trftype.objectname, transforms1[i].languagename);

dumpDropTransform(fpost, &transforms1[i]);

i++;
qstat.transformremoved++;
}
else if (compareNamesAndRelations(&transforms1[i].trftype, &transforms2[j].trftype, transforms1[i].languagename, transforms2[j].languagename) > 0)
{
logDebug("transform for %s.%s language %s: server2", transforms2[i].trftype.schemaname, transforms2[i].trftype.objectname, transforms2[i].languagename);

dumpCreateTransform(fpre, &transforms2[j]);

j++;
qstat.transformadded++;
}
}

freeTransforms(transforms1, ntransforms1);
freeTransforms(transforms2, ntransforms2);
}

static void
quarrelTriggers()
{
Expand Down Expand Up @@ -4525,6 +4615,7 @@ int main(int argc, char *argv[])
{"subscription", required_argument, NULL, 41},
{"table", required_argument, NULL, 31},
{"text-search", required_argument, NULL, 32},
{"transform", required_argument, NULL, 44},
{"trigger", required_argument, NULL, 33},
{"type", required_argument, NULL, 34},
{"view", required_argument, NULL, 35},
Expand Down Expand Up @@ -4767,6 +4858,10 @@ int main(int argc, char *argv[])
gopts.foreigntable = parseBoolean("foreign-table", optarg);
gopts_given.foreigntable = true;
break;
case 44:
gopts.transform = parseBoolean("transform", optarg);
gopts_given.transform = true;
break;
default:
fprintf(stderr, "Try \"%s --help\" for more information.\n", PGQ_NAME);
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -4854,6 +4949,8 @@ int main(int argc, char *argv[])
options.table = gopts.table;
if (gopts_given.textsearch)
options.textsearch = gopts.textsearch;
if (gopts_given.transform)
options.transform = gopts.transform;
if (gopts_given.trigger)
options.trigger = gopts.trigger;
if (gopts_given.type)
Expand Down Expand Up @@ -5047,6 +5144,8 @@ int main(int argc, char *argv[])
quarrelTextSearchDicts();
quarrelTextSearchConfigs();
}
if (options.transform)
quarrelTransforms();
if (options.statistics)
quarrelStatistics();

Expand Down
2 changes: 2 additions & 0 deletions src/quarrel.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ typedef struct PQLStatistic
int tsparserremoved;
int tstemplateadded;
int tstemplateremoved;
int transformadded;
int transformremoved;
int trgadded;
int trgremoved;
int typeadded;
Expand Down
Loading

0 comments on commit b31ddfa

Please sign in to comment.