Skip to content

Commit

Permalink
Merge branch 'master' into optional_parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
oskar-van-rest committed May 4, 2020
2 parents 568def0 + 1010415 commit d8a68c5
Show file tree
Hide file tree
Showing 21 changed files with 944 additions and 505 deletions.
@@ -0,0 +1,141 @@
/*
* Copyright (C) 2013 - 2020 Oracle and/or its affiliates. All rights reserved.
*/
package oracle.pgql.lang.ddl.propertygraph;

import oracle.pgql.lang.ir.Statement;
import oracle.pgql.lang.ir.StatementType;

import static oracle.pgql.lang.ir.PgqlUtils.printIdentifier;
import static oracle.pgql.lang.ir.PgqlUtils.printLiteral;

public class CreateExternalSchema implements Statement {

private String localSchemaName;

private String url;

private String userName;

private String keystoreAlias;

private String dataSourceName;

public CreateExternalSchema(String localSchemaName, String url, String userName, String keystoreAlias) {
this.localSchemaName = localSchemaName;
this.url = url;
this.userName = userName;
this.keystoreAlias = keystoreAlias;
}

public CreateExternalSchema(String localSchemaName, String dataSourceName) {
this.localSchemaName = localSchemaName;
this.dataSourceName = dataSourceName;
}

public String getLocalSchemaName() {
return localSchemaName;
}

public void setLocalSchemaName(String localSchemaName) {
this.localSchemaName = localSchemaName;
}

public String getDataSourceName() {
return dataSourceName;
}

public void setDataSourceName(String dataSourceName) {
this.dataSourceName = dataSourceName;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getKeystoreAlias() {
return keystoreAlias;
}

public void setKeystoreAlias(String keystoreAlias) {
this.keystoreAlias = keystoreAlias;
}

@Override
public String toString() {
String separator = "\n ";
String result = "CREATE EXTERNAL SCHEMA " + printIdentifier(localSchemaName) + "\nFROM DATABASE";
if (url != null) {
result += separator + "URL " + printLiteral(url);
}
if (userName != null) {
result += separator + "USER " + printLiteral(userName);
}
if (keystoreAlias != null) {
result += separator + "KEYSTORE_ALIAS " + printLiteral(keystoreAlias);
}
if (dataSourceName != null) {
result += separator + "DATA_SOURCE " + printLiteral(dataSourceName);
}
return result;
}

@Override
public StatementType getStatementType() {
return StatementType.CREATE_EXTERNAL_SCHEMA;
}

@Override
public int hashCode() {
return 31;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CreateExternalSchema other = (CreateExternalSchema) obj;
if (dataSourceName == null) {
if (other.dataSourceName != null)
return false;
} else if (!dataSourceName.equals(other.dataSourceName))
return false;
if (keystoreAlias == null) {
if (other.keystoreAlias != null)
return false;
} else if (!keystoreAlias.equals(other.keystoreAlias))
return false;
if (localSchemaName == null) {
if (other.localSchemaName != null)
return false;
} else if (!localSchemaName.equals(other.localSchemaName))
return false;
if (url == null) {
if (other.url != null)
return false;
} else if (!url.equals(other.url))
return false;
if (userName == null) {
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
return false;
return true;
}
}
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2013 - 2020 Oracle and/or its affiliates. All rights reserved.
*/
package oracle.pgql.lang.ddl.propertygraph;

import oracle.pgql.lang.ir.Statement;
import oracle.pgql.lang.ir.StatementType;

import static oracle.pgql.lang.ir.PgqlUtils.printIdentifier;

public class DropExternalSchema implements Statement {

private String schemaName;

public DropExternalSchema(String schemaName) {
this.schemaName = schemaName;
}

public String getGraphName() {
return schemaName;
}

public void setGraphName(String schemaName) {
this.schemaName = schemaName;
}

@Override
public String toString() {
return "DROP EXTERNAL SCHEMA " + printIdentifier(schemaName);
}

@Override
public StatementType getStatementType() {
return StatementType.DROP_EXTERNAL_SCHEMA;
}

@Override
public int hashCode() {
return 31;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DropExternalSchema other = (DropExternalSchema) obj;
if (schemaName == null) {
if (other.schemaName != null)
return false;
} else if (!schemaName.equals(other.schemaName))
return false;
return true;
}
}
Expand Up @@ -9,23 +9,23 @@

public class DropPropertyGraph implements Statement {

private SchemaQualifiedName graphName;
private SchemaQualifiedName schemaName;

public DropPropertyGraph(SchemaQualifiedName graphName) {
this.graphName = graphName;
this.schemaName = graphName;
}

public SchemaQualifiedName getGraphName() {
return graphName;
return schemaName;
}

public void setGraphName(SchemaQualifiedName graphName) {
this.graphName = graphName;
this.schemaName = graphName;
}

@Override
public String toString() {
return "DROP PROPERTY GRAPH " + graphName;
return "DROP PROPERTY GRAPH " + schemaName;
}

@Override
Expand All @@ -47,10 +47,10 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
DropPropertyGraph other = (DropPropertyGraph) obj;
if (graphName == null) {
if (other.graphName != null)
if (schemaName == null) {
if (other.schemaName != null)
return false;
} else if (!graphName.equals(other.graphName))
} else if (!schemaName.equals(other.schemaName))
return false;
return true;
}
Expand Down
Expand Up @@ -5,12 +5,16 @@

import static oracle.pgql.lang.ir.PgqlUtils.printIdentifier;

import oracle.pgql.lang.ir.QueryExpression;
import oracle.pgql.lang.ir.QueryExpression.ExpressionType;
import oracle.pgql.lang.ir.QueryExpression.VarRef;

public class Property {

/**
* The column name. In the future, we may want to support arbitrary expressions.
* The value expression.
*/
String columnName;
QueryExpression valueExpression;

/**
* The property name.
Expand All @@ -20,24 +24,17 @@ public class Property {
/**
* Constructor with column name and property name.
*/
public Property(String columnName, String propertyName) {
this.columnName = columnName;
public Property(QueryExpression valueExpression, String propertyName) {
this.valueExpression = valueExpression;
this.propertyName = propertyName;
}

/**
* Constructor with only a name, which is both the column name and the property name.
*/
public Property(String name) {
this(name, name);
public QueryExpression getValueExpression() {
return valueExpression;
}

public String getColumnName() {
return columnName;
}

public void setColumnName(String columnName) {
this.columnName = columnName;
public void setValueExpression(QueryExpression valueExpression) {
this.valueExpression = valueExpression;
}

public String getPropertyName() {
Expand All @@ -48,12 +45,25 @@ public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}

/**
* @deprecated use getValueExpression() instead
*/
@Deprecated
public String getColumnName() {
if (valueExpression.getExpType() == ExpressionType.VARREF) {
VarRef varRef = (VarRef) valueExpression;
return varRef.getVariable().getName();
} else {
return null;
}
}

@Override
public String toString() {
if (columnName.equals(propertyName)) {
if (getColumnName() != null && getColumnName().equals(propertyName)) {
return printIdentifier(propertyName);
} else {
return printIdentifier(columnName) + " AS " + printIdentifier(propertyName);
return valueExpression + " AS " + printIdentifier(propertyName);
}
}

Expand All @@ -71,16 +81,16 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
Property other = (Property) obj;
if (columnName == null) {
if (other.columnName != null)
return false;
} else if (!columnName.equals(other.columnName))
return false;
if (propertyName == null) {
if (other.propertyName != null)
return false;
} else if (!propertyName.equals(other.propertyName))
return false;
if (valueExpression == null) {
if (other.valueExpression != null)
return false;
} else if (!valueExpression.equals(other.valueExpression))
return false;
return true;
}
}
14 changes: 7 additions & 7 deletions graph-query-ir/src/main/java/oracle/pgql/lang/ir/PgqlUtils.java
Expand Up @@ -509,31 +509,31 @@ private static String printTime(LocalTime time) {
return buf.toString();
}

protected static String printLiteral(double val) {
public static String printLiteral(double val) {
return DECIMAL_FORMAT.format(val);
}

protected static String printLiteral(String val) {
public static String printLiteral(String val) {
return "'" + val.replace("'", "''") + "'";
}

protected static String printLiteral(LocalDate val) {
public static String printLiteral(LocalDate val) {
return "DATE '" + val + "'";
}

protected static String printLiteral(LocalTime val) {
public static String printLiteral(LocalTime val) {
return "TIME '" + printTime(val) + "'";
}

protected static String printLiteral(LocalDateTime val) {
public static String printLiteral(LocalDateTime val) {
return "TIMESTAMP '" + val.toLocalDate() + " " + printTime(val.toLocalTime()) + "'";
}

protected static String printLiteral(OffsetTime val) {
public static String printLiteral(OffsetTime val) {
return "TIME '" + printTime(val.toLocalTime()) + val.getOffset() + "'";
}

protected static String printLiteral(OffsetDateTime val) {
public static String printLiteral(OffsetDateTime val) {
return "TIMESTAMP '" + val.toLocalDate() + " " + printTime(val.toLocalTime()) + val.getOffset() + "'";
}
}
Expand Up @@ -8,5 +8,7 @@ public enum StatementType {
SELECT,
GRAPH_MODIFY,
CREATE_PROPERTY_GRAPH,
DROP_PROPERTY_GRAPH
DROP_PROPERTY_GRAPH,
CREATE_EXTERNAL_SCHEMA,
DROP_EXTERNAL_SCHEMA
}

0 comments on commit d8a68c5

Please sign in to comment.