Skip to content

Commit

Permalink
[Spotless] Applying Google Code Format for legacy directory (pt 2/4) #20
Browse files Browse the repository at this point in the history
 (opensearch-project#1989)

* Spotless apply for legacy pt 2

Signed-off-by: Mitchell Gale <[email protected]>

* spotless apply

Signed-off-by: Mitchell Gale <[email protected]>

* Spotless apply for legacy pt 2

Signed-off-by: Mitchell Gale <[email protected]>

* spotless apply

Signed-off-by: Mitchell Gale <[email protected]>

* updated type

Signed-off-by: Mitchell Gale <[email protected]>

* removed spotless

Signed-off-by: Mitchell Gale <[email protected]>

* add spotless

Signed-off-by: Mitchell Gale <[email protected]>

* removed extra test

Signed-off-by: Mitchell Gale <[email protected]>

---------

Signed-off-by: Mitchell Gale <[email protected]>
Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale committed Aug 22, 2023
1 parent dc6f191 commit 6a5cbf7
Show file tree
Hide file tree
Showing 111 changed files with 9,060 additions and 9,407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,92 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.legacy.antlr.semantic.scope;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.opensearch.sql.legacy.antlr.semantic.types.Type;

/**
* Environment for symbol and its attribute (type) in the current scope
*/
/** Environment for symbol and its attribute (type) in the current scope */
public class Environment {

private final Environment parent;

private final SymbolTable symbolTable;
private final Environment parent;

public Environment(Environment parent) {
this.parent = parent;
this.symbolTable = new SymbolTable();
}
private final SymbolTable symbolTable;

/**
* Define symbol with the type
* @param symbol symbol to define
* @param type type
*/
public void define(Symbol symbol, Type type) {
symbolTable.store(symbol, type);
}
public Environment(Environment parent) {
this.parent = parent;
this.symbolTable = new SymbolTable();
}

/**
* Resolve symbol in the environment
* @param symbol symbol to look up
* @return type if exist
*/
public Optional<Type> resolve(Symbol symbol) {
Optional<Type> type = Optional.empty();
for (Environment cur = this; cur != null; cur = cur.parent) {
type = cur.symbolTable.lookup(symbol);
if (type.isPresent()) {
break;
}
}
return type;
}
/**
* Define symbol with the type
*
* @param symbol symbol to define
* @param type type
*/
public void define(Symbol symbol, Type type) {
symbolTable.store(symbol, type);
}

/**
* Resolve symbol definitions by a prefix.
* @param prefix a prefix of symbol
* @return all symbols with types that starts with the prefix
*/
public Map<String, Type> resolveByPrefix(Symbol prefix) {
Map<String, Type> typeByName = new HashMap<>();
for (Environment cur = this; cur != null; cur = cur.parent) {
typeByName.putAll(cur.symbolTable.lookupByPrefix(prefix));
}
return typeByName;
/**
* Resolve symbol in the environment
*
* @param symbol symbol to look up
* @return type if exist
*/
public Optional<Type> resolve(Symbol symbol) {
Optional<Type> type = Optional.empty();
for (Environment cur = this; cur != null; cur = cur.parent) {
type = cur.symbolTable.lookup(symbol);
if (type.isPresent()) {
break;
}
}
return type;
}

/**
* Resolve all symbols in the namespace.
* @param namespace a namespace
* @return all symbols in the namespace
*/
public Map<String, Type> resolveAll(Namespace namespace) {
Map<String, Type> result = new HashMap<>();
for (Environment cur = this; cur != null; cur = cur.parent) {
// putIfAbsent ensures inner most definition will be used (shadow outers)
cur.symbolTable.lookupAll(namespace).forEach(result::putIfAbsent);
}
return result;
/**
* Resolve symbol definitions by a prefix.
*
* @param prefix a prefix of symbol
* @return all symbols with types that starts with the prefix
*/
public Map<String, Type> resolveByPrefix(Symbol prefix) {
Map<String, Type> typeByName = new HashMap<>();
for (Environment cur = this; cur != null; cur = cur.parent) {
typeByName.putAll(cur.symbolTable.lookupByPrefix(prefix));
}
return typeByName;
}

/** Current environment is root and no any symbol defined */
public boolean isEmpty(Namespace namespace) {
for (Environment cur = this; cur != null; cur = cur.parent) {
if (!cur.symbolTable.isEmpty(namespace)) {
return false;
}
}
return true;
/**
* Resolve all symbols in the namespace.
*
* @param namespace a namespace
* @return all symbols in the namespace
*/
public Map<String, Type> resolveAll(Namespace namespace) {
Map<String, Type> result = new HashMap<>();
for (Environment cur = this; cur != null; cur = cur.parent) {
// putIfAbsent ensures inner most definition will be used (shadow outers)
cur.symbolTable.lookupAll(namespace).forEach(result::putIfAbsent);
}
return result;
}

public Environment getParent() {
return parent;
/** Current environment is root and no any symbol defined */
public boolean isEmpty(Namespace namespace) {
for (Environment cur = this; cur != null; cur = cur.parent) {
if (!cur.symbolTable.isEmpty(namespace)) {
return false;
}
}
return true;
}

public Environment getParent() {
return parent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.legacy.antlr.semantic.scope;

/**
* Namespace of symbol to avoid naming conflict
*/
/** Namespace of symbol to avoid naming conflict */
public enum Namespace {
FIELD_NAME("Field"),
FUNCTION_NAME("Function"),
OPERATOR_NAME("Operator");

FIELD_NAME("Field"),
FUNCTION_NAME("Function"),
OPERATOR_NAME("Operator");

private final String name;

Namespace(String name) {
this.name = name;
}
private final String name;

@Override
public String toString() {
return name;
}
Namespace(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.legacy.antlr.semantic.types.operator;

import static org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchDataType.TYPE_ERROR;
Expand All @@ -13,35 +12,32 @@
import org.opensearch.sql.legacy.antlr.semantic.types.Type;
import org.opensearch.sql.legacy.antlr.semantic.types.base.OpenSearchIndex;

/**
* Join operator
*/
/** Join operator */
public enum JoinOperator implements Type {
JOIN;

@Override
public String getName() {
return name();
}

@Override
public Type construct(List<Type> others) {
Optional<Type> isAnyNonIndexType = others.stream().
filter(type -> !(type instanceof OpenSearchIndex)).
findAny();
if (isAnyNonIndexType.isPresent()) {
return TYPE_ERROR;
}
return others.get(0);
}

@Override
public String usage() {
return "Please join index with other index or its nested field.";
}

@Override
public String toString() {
return "Operator [" + getName() + "]";
JOIN;

@Override
public String getName() {
return name();
}

@Override
public Type construct(List<Type> others) {
Optional<Type> isAnyNonIndexType =
others.stream().filter(type -> !(type instanceof OpenSearchIndex)).findAny();
if (isAnyNonIndexType.isPresent()) {
return TYPE_ERROR;
}
return others.get(0);
}

@Override
public String usage() {
return "Please join index with other index or its nested field.";
}

@Override
public String toString() {
return "Operator [" + getName() + "]";
}
}
Loading

0 comments on commit 6a5cbf7

Please sign in to comment.