Exemplo n.º 1
0
  public boolean hasSuffix(QualifiedName suffix) {
    if (parts.size() < suffix.getParts().size()) {
      return false;
    }

    int start = parts.size() - suffix.getParts().size();

    return parts.subList(start, parts.size()).equals(suffix.getParts());
  }
Exemplo n.º 2
0
 private static boolean isColumnReference(QualifiedName name, RelationType relation) {
   while (name.getPrefix().isPresent()) {
     name = name.getPrefix().get();
     if (!relation.resolveFields(name).isEmpty()) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 3
0
    @Override
    protected String visitFunctionCall(FunctionCall node, Boolean unmangleNames) {
      StringBuilder builder = new StringBuilder();

      String arguments = joinExpressions(node.getArguments(), unmangleNames);
      if (node.getArguments().isEmpty() && "count".equalsIgnoreCase(node.getName().getSuffix())) {
        arguments = "*";
      }
      if (node.isDistinct()) {
        arguments = "DISTINCT " + arguments;
      }

      if (unmangleNames && node.getName().toString().startsWith(QueryUtil.FIELD_REFERENCE_PREFIX)) {
        checkState(
            node.getArguments().size() == 1, "Expected only one argument to field reference");
        QualifiedName name =
            QualifiedName.of(QueryUtil.unmangleFieldReference(node.getName().toString()));
        builder.append(arguments).append(".").append(name);
      } else {
        builder
            .append(formatQualifiedName(node.getName()))
            .append('(')
            .append(arguments)
            .append(')');
      }

      if (node.getWindow().isPresent()) {
        builder.append(" OVER ").append(visitWindow(node.getWindow().get(), unmangleNames));
      }

      return builder.toString();
    }
Exemplo n.º 4
0
 private static String formatQualifiedName(QualifiedName name) {
   List<String> parts = new ArrayList<>();
   for (String part : name.getParts()) {
     parts.add(formatIdentifier(part));
   }
   return Joiner.on('.').join(parts);
 }
Exemplo n.º 5
0
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    QualifiedNameReference that = (QualifiedNameReference) o;

    if (!name.equals(that.name)) {
      return false;
    }

    return true;
  }
Exemplo n.º 6
0
 @Override
 public int hashCode() {
   return name.hashCode();
 }
Exemplo n.º 7
0
 public QualifiedName getSuffix() {
   return QualifiedName.of(Iterables.getLast(name.getParts()));
 }