private static HashMap<String, String> buildTableMetadata(
      String tableName, List<Column> columns, String encoding) {
    HashMap<String, String> options = new HashMap<String, String>();
    options.put(EvaluatorIterator.COLUMNS_COUNT, String.valueOf(columns.size()));
    options.put(EvaluatorIterator.TABLENAME, tableName);
    options.put(EvaluatorIterator.ENCODING, encoding);

    for (int i = 0; i < columns.size(); i++) {
      Column column = columns.get(i);
      options.put(EvaluatorIterator.createColumnName(EvaluatorIterator.NAME, i), column.getName());
      if (!SQLStringVisitor.getRecordName(column).equals(AccumuloMetadataProcessor.ROWID)) {
        options.put(
            EvaluatorIterator.createColumnName(EvaluatorIterator.CF, i),
            column.getProperty(AccumuloMetadataProcessor.CF, false));
        if (column.getProperty(AccumuloMetadataProcessor.CQ, false) != null) {
          options.put(
              EvaluatorIterator.createColumnName(EvaluatorIterator.CQ, i),
              column.getProperty(AccumuloMetadataProcessor.CQ, false));
        }
        if (column.getProperty(AccumuloMetadataProcessor.VALUE_IN, false) != null) {
          options.put(
              EvaluatorIterator.createColumnName(EvaluatorIterator.VALUE_IN, i),
              column.getProperty(AccumuloMetadataProcessor.VALUE_IN, false));
        }
      }
      options.put(
          EvaluatorIterator.createColumnName(EvaluatorIterator.DATA_TYPE, i),
          column.getDatatype().getJavaClassName());
    }
    return options;
  }
示例#2
0
  /**
   * method to execute the supplied query
   *
   * @param query the query object.
   * @param maxBatchSize the max batch size.
   */
  @Override
  public void execute() throws TranslatorException {
    String ctxName = this.searchDetails.getContextName();
    String filter = this.searchDetails.getContextFilter();
    if (ctxName == null || filter == null || this.ctrls == null) {
      throw new TranslatorException(
          "Search context, filter, or controls were null. Cannot execute search."); //$NON-NLS-1$
    }

    ArrayList<Column> attributeList = searchDetails.getElementList();

    // determine if there is an array value to unwrap
    for (int i = 0; i < attributeList.size(); i++) {
      Column col = attributeList.get(i);
      if (Boolean.valueOf(col.getProperty(LDAPExecutionFactory.UNWRAP, false))) {
        if (unwrapPos > -1) {
          throw new TranslatorException(
              LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12014, col, attributeList.get(unwrapPos)));
        }
        unwrapPos = i;
      }
    }

    setRequestControls(null);
    // Execute the search.
    executeSearch();
  }
示例#3
0
  @Test
  public void testAlterTableRemoveColumnOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer OPTIONS (NULL_VALUE_COUNT 12, FOO 'BAR'), e2 varchar, e3 date);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(DROP NULL_VALUE_COUNT);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(DROP FOO);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS( ADD x 'y');";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    Column c = table.getColumnByName("e1");
    assertNotNull(c);

    assertNull(c.getProperty("FOO", false));
    assertEquals(-1, c.getNullValues());
    assertEquals("y", c.getProperty("x", false));
  }
  @Override
  public void visit(DerivedColumn obj) {
    this.currentAlias = buildAlias(obj.getAlias());
    visitNode(obj.getExpression());

    Column column = (Column) this.onGoingExpression.pop();

    String CF = column.getProperty(AccumuloMetadataProcessor.CF, false);
    String CQ = column.getProperty(AccumuloMetadataProcessor.CQ, false);
    if (CQ != null) {
      this.keybasedColumnMap.put(CF + "/" + CQ, column); // $NON-NLS-1$
    } else {
      this.keybasedColumnMap.put(CF, column);
    }

    // no expressions in select are allowed.
    this.selectColumns.add(column);
  }
示例#5
0
  @Test
  public void testAlterTableAddColumnOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date);"
            + "ALTER FOREIGN TABLE G1 OPTIONS(ADD CARDINALITY 12);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(ADD NULL_VALUE_COUNT 12);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(ADD FOO 'BAR');";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    assertEquals(12, table.getCardinality());
    Column c = table.getColumnByName("e1");
    assertNotNull(c);

    assertEquals("BAR", c.getProperty("FOO", false));
    assertEquals(12, c.getNullValues());
  }
示例#6
0
  private Object convertSingleValue(
      Column modelElement, String modelAttrName, Class<?> modelAttrClass, Object objResult)
      throws TranslatorException, InvalidNameException {
    if (objResult == null) {
      return null;
    }
    // GHH 20080326 - if attribute is not a string or empty, just
    // return null.
    if (!(objResult instanceof String)) {
      return objResult;
    }

    String strResult = (String) objResult;
    // MPW - 3.9.07 - Also return NULL when attribute is unset or empty string.
    // There is no way to differentiate between being unset and being the empty string.
    if (strResult.equals("")) { // $NON-NLS-1$
      return null;
    }

    // MPW: 3-11-07: Added support for java.lang.Integer conversion.
    if (TypeFacility.RUNTIME_TYPES.TIMESTAMP.equals(modelAttrClass)) {
      String timestampFormat = modelElement.getFormat();
      if (timestampFormat == null) {
        timestampFormat = LDAPConnectorConstants.ldapTimestampFormat;
      }
      SimpleDateFormat dateFormat = new SimpleDateFormat(timestampFormat);
      try {
        Date dateResult = dateFormat.parse(strResult);
        Timestamp tsResult = new Timestamp(dateResult.getTime());
        return tsResult;
      } catch (ParseException pe) {
        throw new TranslatorException(
            pe,
            LDAPPlugin.Util.getString(
                "LDAPSyncQueryExecution.timestampParseFailed", modelAttrName)); // $NON-NLS-1$
      }

      //	TODO: Extend support for more types in the future.
      // Specifically, add support for byte arrays, since that's actually supported
      // in the underlying data source.
    }

    // extract rdn
    String type = modelElement.getProperty(LDAPExecutionFactory.RDN_TYPE, false);
    if (type != null) {
      String prefix = modelElement.getProperty(LDAPExecutionFactory.DN_PREFIX, false);
      LdapName name = new LdapName(strResult);
      if (prefix != null) {
        if (!name.getPrefix(name.size() - 1).toString().equals(prefix)) {
          throw new InvalidNameException();
        }
      } else if (name.size() > 1) {
        throw new InvalidNameException();
      }
      Rdn rdn = name.getRdn(name.size() - 1);
      if (!rdn.getType().equals(type)) {
        throw new InvalidNameException();
      }
      return rdn.getValue();
    }

    return strResult; // the Teiid type conversion logic will handle refine from here if necessary
  }