예제 #1
0
 static ColumnMetadata build(TableMetadata tm, Row row) {
   try {
     String name = row.getString(COLUMN_NAME);
     AbstractType<?> t = TypeParser.parse(row.getString(VALIDATOR));
     ColumnMetadata cm = new ColumnMetadata(tm, name, Codec.rawTypeToDataType(t), row);
     tm.add(cm);
     return cm;
   } catch (RequestValidationException e) {
     // The server will have validated the type
     throw new RuntimeException(e);
   }
 }
  CqlRecordWriter(Configuration conf) {
    this.conf = conf;
    this.queueSize =
        conf.getInt(ColumnFamilyOutputFormat.QUEUE_SIZE, 32 * FBUtilities.getAvailableProcessors());
    batchThreshold = conf.getLong(ColumnFamilyOutputFormat.BATCH_THRESHOLD, 32);
    this.clients = new HashMap<>();

    try {
      String keyspace = ConfigHelper.getOutputKeyspace(conf);
      try (Session client =
          CqlConfigHelper.getOutputCluster(ConfigHelper.getOutputInitialAddress(conf), conf)
              .connect(keyspace)) {
        ringCache = new NativeRingCache(conf);
        if (client != null) {
          TableMetadata tableMetadata =
              client
                  .getCluster()
                  .getMetadata()
                  .getKeyspace(client.getLoggedKeyspace())
                  .getTable(ConfigHelper.getOutputColumnFamily(conf));
          clusterColumns = tableMetadata.getClusteringColumns();
          partitionKeyColumns = tableMetadata.getPartitionKey();

          String cqlQuery = CqlConfigHelper.getOutputCql(conf).trim();
          if (cqlQuery.toLowerCase().startsWith("insert"))
            throw new UnsupportedOperationException(
                "INSERT with CqlRecordWriter is not supported, please use UPDATE/DELETE statement");
          cql = appendKeyWhereClauses(cqlQuery);
        } else {
          throw new IllegalArgumentException("Invalid configuration specified " + conf);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
예제 #3
0
 /**
  * Returns a CQL query representing this index.
  *
  * <p>This method returns a single 'CREATE INDEX' query corresponding to this index definition.
  *
  * @return the 'CREATE INDEX' query corresponding to this index.
  */
 public String asCQLQuery() {
   TableMetadata table = column.getTable();
   return String.format(
       "CREATE INDEX %s ON %s.%s (%s)",
       name, table.getKeyspace().getName(), table.getName(), column.getName());
 }