Package org.eigenbase.sql

Examples of org.eigenbase.sql.SqlDialect


        connection = dataSource.getConnection();
        DatabaseMetaData metaData = connection.getMetaData();
        String productName = metaData.getDatabaseProductName();
        String productVersion = metaData.getDatabaseProductVersion();
        List key = ImmutableList.of(productName, productVersion);
        SqlDialect dialect = map.get(key);
        if (dialect == null) {
          final SqlDialect.DatabaseProduct product =
              SqlDialect.getProduct(productName, productVersion);
          dialect =
              new SqlDialect(
                  product,
                  productName,
                  metaData.getIdentifierQuoteString());
          map.put(key, dialect);
        }
View Full Code Here


      DataSource dataSource,
      String catalog,
      String schema) {
    final Expression expression =
        Schemas.subSchemaExpression(parentSchema, name, JdbcSchema.class);
    final SqlDialect dialect = createDialect(dataSource);
    final JdbcConvention convention =
        JdbcConvention.of(dialect, expression, name);
    return new JdbcSchema(dataSource, dialect, convention, catalog, schema);
  }
View Full Code Here

        connection = dataSource.getConnection();
        DatabaseMetaData metaData = connection.getMetaData();
        String productName = metaData.getDatabaseProductName();
        String productVersion = metaData.getDatabaseProductVersion();
        List key = ImmutableList.of(productName, productVersion);
        SqlDialect dialect = map.get(key);
        if (dialect == null) {
          final SqlDialect.DatabaseProduct product =
              SqlDialect.getProduct(productName, productVersion);
          dialect =
              new SqlDialect(
                  product,
                  productName,
                  metaData.getIdentifierQuoteString());
          map.put(key, dialect);
        }
View Full Code Here

      DataSource dataSource,
      String catalog,
      String schema) {
    final Expression expression =
        Schemas.subSchemaExpression(parentSchema, name, JdbcSchema.class);
    final SqlDialect dialect = createDialect(dataSource);
    final JdbcConvention convention =
        JdbcConvention.of(dialect, expression, name);
    return new JdbcSchema(dataSource, dialect, convention, catalog, schema);
  }
View Full Code Here

    for (Node node : nodes) {
      if (BitSets.range(node.startCol, node.endCol).intersects(columnSet)) {
        use(usedNodes, node);
      }
    }
    final SqlDialect dialect = SqlDialect.DatabaseProduct.OPTIQ.getDialect();
    final StringBuilder buf = new StringBuilder("SELECT ");
    final StringBuilder groupBuf = new StringBuilder("\nGROUP BY ");
    int k = 0;
    final Set<String> columnNames = Sets.newHashSet();
    for (int i : BitSets.toIter(groupSet)) {
      if (k++ > 0) {
        buf.append(", ");
        groupBuf.append(", ");
      }
      final Column column = columns.get(i);
      dialect.quoteIdentifier(buf, column.identifiers());
      dialect.quoteIdentifier(groupBuf, column.identifiers());
      final String fieldName = uniqueColumnNames.get(i);
      columnNames.add(fieldName);
      if (!column.alias.equals(fieldName)) {
        buf.append(" AS ");
        dialect.quoteIdentifier(buf, fieldName);
      }
    }
    int m = 0;
    for (Measure measure : aggCallList) {
      if (k++ > 0) {
        buf.append(", ");
      }
      buf.append(measure.agg.getName())
          .append("(");
      if (measure.args.isEmpty()) {
        buf.append("*");
      } else {
        int z = 0;
        for (Column arg : measure.args) {
          if (z++ > 0) {
            buf.append(", ");
          }
          dialect.quoteIdentifier(buf, arg.identifiers());
        }
      }
      buf.append(") AS ");
      String measureName;
      while (!columnNames.add(measureName = "m" + m)) {
        ++m;
      }
      dialect.quoteIdentifier(buf, measureName);
    }
    buf.append("\nFROM ");
    for (Node node : usedNodes) {
      if (node.parent != null) {
        buf.append("\nJOIN ");
      }
      dialect.quoteIdentifier(buf, node.scan.getTable().getQualifiedName());
      buf.append(" AS ");
      dialect.quoteIdentifier(buf, node.alias);
      if (node.parent != null) {
        buf.append(" ON ");
        k = 0;
        for (IntPair pair : node.link) {
          if (k++ > 0) {
            buf.append(" AND ");
          }
          final Column left = columns.get(node.parent.startCol + pair.source);
          dialect.quoteIdentifier(buf, left.identifiers());
          buf.append(" = ");
          final Column right = columns.get(node.startCol + pair.target);
          dialect.quoteIdentifier(buf, right.identifiers());
        }
      }
    }
    if (OptiqPrepareImpl.DEBUG) {
      System.out.println("Lattice SQL:\n" + buf);
View Full Code Here

      DataSource dataSource,
      String catalog,
      String schema) {
    final Expression expression =
        Schemas.subSchemaExpression(parentSchema, name, JdbcSchema.class);
    final SqlDialect dialect = createDialect(dataSource);
    final JdbcConvention convention =
        JdbcConvention.of(dialect, expression, name);
    return new JdbcSchema(dataSource, dialect, convention, catalog, schema);
  }
View Full Code Here

    final Map<List, SqlDialect> map = new HashMap<List, SqlDialect>();

    public static final DialectPool INSTANCE = new DialectPool();

    SqlDialect get(DataSource dataSource) {
      final SqlDialect sqlDialect = map0.get(dataSource);
      if (sqlDialect != null) {
        return sqlDialect;
      }
      Connection connection = null;
      try {
        connection = dataSource.getConnection();
        DatabaseMetaData metaData = connection.getMetaData();
        String productName = metaData.getDatabaseProductName();
        String productVersion = metaData.getDatabaseProductVersion();
        List key = ImmutableList.of(productName, productVersion);
        SqlDialect dialect = map.get(key);
        if (dialect == null) {
          final SqlDialect.DatabaseProduct product =
              SqlDialect.getProduct(productName, productVersion);
          dialect =
              new SqlDialect(
                  product,
                  productName,
                  metaData.getIdentifierQuoteString());
          map.put(key, dialect);
          map0.put(dataSource, dialect);
View Full Code Here

    for (Node node : nodes) {
      if (BitSets.range(node.startCol, node.endCol).intersects(columnSet)) {
        use(usedNodes, node);
      }
    }
    final SqlDialect dialect = SqlDialect.DatabaseProduct.OPTIQ.getDialect();
    final StringBuilder buf = new StringBuilder("SELECT ");
    final StringBuilder groupBuf = new StringBuilder("\nGROUP BY ");
    int k = 0;
    final Set<String> columnNames = Sets.newHashSet();
    for (int i : BitSets.toIter(groupSet)) {
      if (k++ > 0) {
        buf.append(", ");
        groupBuf.append(", ");
      }
      final Column column = columns.get(i);
      dialect.quoteIdentifier(buf, column.identifiers());
      dialect.quoteIdentifier(groupBuf, column.identifiers());
      final String fieldName = uniqueColumnNames.get(i);
      columnNames.add(fieldName);
      if (!column.alias.equals(fieldName)) {
        buf.append(" AS ");
        dialect.quoteIdentifier(buf, fieldName);
      }
    }
    int m = 0;
    for (Measure measure : aggCallList) {
      if (k++ > 0) {
        buf.append(", ");
      }
      buf.append(measure.agg.getName())
          .append("(");
      if (measure.args.isEmpty()) {
        buf.append("*");
      } else {
        int z = 0;
        for (Column arg : measure.args) {
          if (z++ > 0) {
            buf.append(", ");
          }
          dialect.quoteIdentifier(buf, arg.identifiers());
        }
      }
      buf.append(") AS ");
      String measureName;
      while (!columnNames.add(measureName = "m" + m)) {
        ++m;
      }
      dialect.quoteIdentifier(buf, measureName);
    }
    buf.append("\nFROM ");
    for (Node node : usedNodes) {
      if (node.parent != null) {
        buf.append("\nJOIN ");
      }
      dialect.quoteIdentifier(buf, node.scan.getTable().getQualifiedName());
      buf.append(" AS ");
      dialect.quoteIdentifier(buf, node.alias);
      if (node.parent != null) {
        buf.append(" ON ");
        k = 0;
        for (IntPair pair : node.link) {
          if (k++ > 0) {
            buf.append(" AND ");
          }
          final Column left = columns.get(node.parent.startCol + pair.source);
          dialect.quoteIdentifier(buf, left.identifiers());
          buf.append(" = ");
          final Column right = columns.get(node.startCol + pair.target);
          dialect.quoteIdentifier(buf, right.identifiers());
        }
      }
    }
    if (OptiqPrepareImpl.DEBUG) {
      System.out.println("Lattice SQL:\n" + buf);
View Full Code Here

TOP

Related Classes of org.eigenbase.sql.SqlDialect

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.