Search code examples
javaamazon-redshiftquerydsl

QueryDSL with Redshift setup


I'm trying to add QueryDSL to a project that uses Amazon Redshift. I'm not sure QueryDSL even supports Redshift, and I'm probably doing a lot wrong here. I'm getting compilation errors in the Q classes, see below relevant excerpts:

TABLE DDL (REDSHIFT) (NOTE the users_follow table lack of an id column and the binary primary key)

CREATE TABLE users_follow (
    user_id1 INT8 NOT NULL,
    user_id2 INT8 NOT NULL,
    active INT2 NOT NULL,
    created_at TIMESTAMP NOT NULL,
    modified_at TIMESTAMP NOT NULL,
    PRIMARY KEY (user_id1, user_id2),
    FOREIGN KEY (user_id1) REFERENCES users (id),
    FOREIGN KEY (user_id2) REFERENCES users (id)
)

CREATE TABLE users (
    id INT8 NOT NULL,
    username VARCHAR(255),
    PRIMARY KEY (id)
)

POM DEPENDENCIES SECTION

    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-sql</artifactId>
        <version>4.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-sql-codegen</artifactId>
        <version>4.1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-sql-spring</artifactId>
        <version>4.1.0</version>
    </dependency>

POM PLUGINS SECTION

        <plugin>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-maven-plugin</artifactId>
            <version>4.1.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>export</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <jdbcDriver>com.amazon.redshift.core.jdbc41.PGJDBC41Driver</jdbcDriver>
                <jdbcUrl>jdbc:redshift://aUrl.com:5439/aSchema</jdbcUrl>
                <jdbcPassword>aPassword</jdbcPassword>
                <jdbcUser>aUser</jdbcUser>
                <packageName>com.myproject.domain</packageName>
                <targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
                <sourceFolder>${project.basedir}/target/generated-sources/java</sourceFolder>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>com.amazonaws</groupId>
                    <artifactId>redshift</artifactId>
                    <version>${redshift.version}</version>
                </dependency>
            </dependencies>
        </plugin>

OUTPUT FROM mvn clean install -Dmaven.test.skip=true -e -X

...

[INFO] Exported users_follow successfully

...

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] path/target/generated-sources/java/com/myproject/domain/QUsersFollow.java:[43,109] cannot find symbol
  symbol:   variable id
  location: class com.myproject.domain.QUsersFollow
[ERROR] path/target/generated-sources/java/com/myproject/domain/QUsersFollow.java:[45,109] cannot find symbol
  symbol:   variable id
  location: class com.myproject.domain.QUsersFollow
[INFO] 18 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.210 s
[INFO] Finished at: 2016-05-09T04:00:53+00:00
[INFO] Final Memory: 40M/373M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project analytics-service: Compilation failure: Compilation failure:
[ERROR] path/target/generated-sources/java/com/myproject/domain/QUsersFollow.java:[43,109] cannot find symbol
[ERROR] symbol:   variable id
[ERROR] location: class com.myproject.domain.QUsersFollow
[ERROR] path/target/generated-sources/java/com/myproject/domain/QUsersFollow.java:[45,109] cannot find symbol
[ERROR] symbol:   variable id
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project analytics-service: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:972)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more

GENERATED QCLASS (NOTE cannot resolve symbol 'id')

package com.myproject.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.Generated;
import com.querydsl.core.types.Path;

import com.querydsl.sql.ColumnMetadata;
import java.sql.Types;

/**
 * QUsersFollow is a Querydsl query type for QUsersFollow
 */
@Generated("com.querydsl.sql.codegen.MetaDataSerializer")
public class QUsersFollow extends com.querydsl.sql.RelationalPathBase<QUsersFollow> {

    private static final long serialVersionUID = 463786116;

    public static final QUsersFollow usersFollow = new QUsersFollow("users_follow");

    public final NumberPath<Short> active = createNumber("active", Short.class);

    public final DateTimePath<java.sql.Timestamp> createdAt = createDateTime("createdAt", java.sql.Timestamp.class);

    public final DateTimePath<java.sql.Timestamp> modifiedAt = createDateTime("modifiedAt", java.sql.Timestamp.class);

    public final NumberPath<Long> userId1 = createNumber("userId1", Long.class);

    public final NumberPath<Long> userId2 = createNumber("userId2", Long.class);

    public final com.querydsl.sql.PrimaryKey<QUsersFollow> usersFollowNewPkey = createPrimaryKey(userId1, userId2);

    public final com.querydsl.sql.ForeignKey<QUsers> usersFollowNewUserId1Fkey = createForeignKey(userId1, "id");

    public final com.querydsl.sql.ForeignKey<QUsers> usersFollowNewUserId2Fkey = createForeignKey(userId2, "id");

    public final com.querydsl.sql.ForeignKey<QUsersFollow> _usersFollowNewUserId1Fkey = createInvForeignKey(id, "user_id1"); //cannot resolve symbol 'id'

    public final com.querydsl.sql.ForeignKey<QUsersFollow> _usersFollowNewUserId2Fkey = createInvForeignKey(id, "user_id2"); //cannot resolve symbol 'id'

    public QUsersFollow(String variable) {
        super(QUsersFollow.class, forVariable(variable), "public", "users_follow");
        addMetadata();
    }

    public QUsersFollow(String variable, String schema, String table) {
        super(QUsersFollow.class, forVariable(variable), schema, table);
        addMetadata();
    }

    public QUsersFollow(Path<? extends QUsersFollow> path) {
        super(path.getType(), path.getMetadata(), "public", "users_follow");
        addMetadata();
    }

    public QUsersFollow(PathMetadata metadata) {
        super(QUsersFollow.class, metadata, "public", "users_follow");
        addMetadata();
    }

    public void addMetadata() {
        addMetadata(active, ColumnMetadata.named("active").withIndex(3).ofType(Types.SMALLINT).withSize(5).notNull());
        addMetadata(createdAt, ColumnMetadata.named("created_at").withIndex(4).ofType(Types.TIMESTAMP).withSize(29).withDigits(6).notNull());
        addMetadata(modifiedAt, ColumnMetadata.named("modified_at").withIndex(5).ofType(Types.TIMESTAMP).withSize(29).withDigits(6).notNull());
        addMetadata(userId1, ColumnMetadata.named("user_id1").withIndex(1).ofType(Types.BIGINT).withSize(19).notNull());
        addMetadata(userId2, ColumnMetadata.named("user_id2").withIndex(2).ofType(Types.BIGINT).withSize(19).notNull());
    }

}

Solution

  • QueryDSL devs: Redshift is not a supported DB, I'd say the database metadata is not provided properly by the JDBC driver.

    https://github.com/querydsl/querydsl/issues/1880