text:
package org.apache.flink.table.runtime.stream.table

import org.apache.flink.api.common.typeinfo.TypeInformation
import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.table.api._
import org.apache.flink.table.api.bridge.scala._
import org.apache.flink.table.api.internal.TableEnvironmentInternal
import org.apache.flink.table.expressions.utils.Func20
import org.apache.flink.table.functions.aggfunctions.CountAggFunction
import org.apache.flink.table.runtime.utils.JavaUserDefinedAggFunctions.{CountDistinct, WeightedAvg}
import org.apache.flink.table.runtime.utils.{StreamITCase, StreamTestData, StreamingWithStateTestBase}
import org.apache.flink.types.Row

import org.junit.Assert._
import org.junit.{Before, Test}

import scala.collection.mutable

class JoinITCase extends StreamingWithStateTestBase {

  var env: StreamExecutionEnvironment = _
  var tEnv: StreamTableEnvironment = _

  @Before
  def setup(): Unit = {
    env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setStateBackend(getStateBackend)
    val settings = EnvironmentSettings.newInstance().useOldPlanner().build
    tEnv = StreamTableEnvironment.create(env, settings)

    StreamITCase.clear
  }

  @Test
  def testInnerJoinOutputWithPk(): Unit = {
    // data input
    val data1 = List(
      (0, 0),
      (1, 0),
      (1, 1),
      (2, 2),
      (3, 3),
      (4, 4),
      (5, 4),
      (5, 5),
      (5, null),
      (6, null)
    )

    val data2 = List(
      (0L, 0),
      (1L, 1),
      (2L, 0),
      (2L, 1),
      (2L, 2),
      (3L, 3),
      (4L, 4),
      (5L, 4),
      (5L, 5),
      (6L, 6),
      (7L, null),
      (8L, null)
    )

    val leftTable = env.fromCollection(data1).toTable(tEnv, 'a, 'b)
    val rightTable = env.fromCollection(data2).toTable(tEnv, 'bb, 'c)

    tEnv.asInstanceOf[TableEnvironmentInternal].registerTableSinkInternal(
      "upsertSink",
      new TestUpsertSink(Array("a,b"), false).configure(
        Array[String]("a", "b", "c"),
        Array[TypeInformation[_]](Types.INT, Types.LONG, Types.LONG)))

    val leftTableWithPk = leftTable
      .groupBy('a)
      .select('a, 'b.count as 'b)

    val rightTableWithPk = rightTable
        .groupBy('bb)
        .select('bb, 'c.count as 'c)

    leftTableWithPk
      .join(rightTableWithPk, 'b === 'bb)
      .select('a, 'b, 'c)
      .insertInto("upsertSink")

    tEnv.execute("job name")
    val results = RowCollector.getAndClearValues
    val retracted = RowCollector.upsertResults(results, Array(0, 1))

    val expected = Seq("0,1,1", "1,2,3", "2,1,1", "3,1,1", "4,1,1", "5,2,3", "6,0,1")
    assertEquals(expected.sorted, retracted.sorted)
  }

  @Test
  def testInnerJoinOutputWithoutPk(): Unit = {
    // data input

    val data1 = List(
      (0, 0),
      (1, 0),
      (1, 1),
      (2, 2),
      (3, 3),
      (4, 4),
      (5, 4),
      (5, 5)
    )

    val data2 = List(
      (1, 1, 1),
      (1, 1, 1),
      (1, 1, 1),
      (1, 1, 1),
      (2, 2, 2),
      (3, 3, 3),
      (4, 4, 4),
      (5, 5, 5),
      (5, 5, 5),
      (6, 6, 6)
    )

    val leftTable = env.fromCollection(data1).toTable(tEnv, 'a, 'b)
    val rightTable = env.fromCollection(data2).toTable(tEnv, 'bb, 'c, 'd)

    tEnv.asInstanceOf[TableEnvironmentInternal].registerTableSinkInternal(
      "retractSink",
      new TestRetractSink().configure(
        Array[String]("a", "b", "c", "d"),
        Array[TypeInformation[_]](Types.INT, Types.INT, Types.INT, Types.INT)))

    val leftTableWithPk = leftTable
      .groupBy('a)
      .select('a, 'b.max as 'b)

    leftTableWithPk
      .join(rightTable, 'a === 'bb && ('a < 4 || 'a > 4))
      .select('a, 'b, 'c, 'd)
      .insertInto("retractSink")

    tEnv.execute("job name")
    val results = RowCollector.getAndClearValues
    val retracted = RowCollector.retractResults(results)
    val expected = Seq("1,1,1,1", "1,1,1,1", "1,1,1,1", "1,1,1,1", "2,2,2,2", "3,3,3,3",
                       "5,5,5,5", "5,5,5,5")
    assertEquals(expected.sorted, retracted.sorted)
  }

  @Test
  def testInnerJoinWithProcTimeAttributeOutput() {

    val data1 = List(
      (1L, 1, "LEFT:Hi"),
      (2L, 2, "LEFT:Hello"),
      (4L, 2, "LEFT:Hello"),
      (8L, 3, "LEFT:Hello world"),
      (16L, 3, "LEFT:Hello world"))

    val data2 = List(
      (1L, 1, "RIGHT:Hi"),
      (2L, 2, "RIGHT:Hello"),
      (4L, 2, "RIGHT:Hello"),
      (8L, 3, "RIGHT:Hello world"),
      (16L, 3, "RIGHT:Hello world"))

    StreamITCase.testResults = mutable.MutableList()

    val stream1 = env
      .fromCollection(data1)
    val stream2 = env
      .fromCollection(data2)

    val table1 = stream1.toTable(tEnv, 'long_l, 'int_l, 'string_l, 'proctime_l.proctime)
    val table2 = stream2.toTable(tEnv, 'long_r, 'int_r, 'string_r)
    val countFun = new CountAggFunction
    val weightAvgFun = new WeightedAvg
    val countDistinct = new CountDistinct

    val table = table1
      .join(table2, 'long_l === 'long_r)
      .select('long_l as 'long, 'int_r as 'int, 'string_r as 'string, 'proctime_l as 'proctime)

    val windowedTable = table
      .window(Tumble over 5.milli on 'proctime as 'w)
      .groupBy('w, 'string)
      .select('string, countFun('string), 'int.avg, weightAvgFun('long, 'int),
              weightAvgFun('int, 'int), 'int.min, 'int.max, 'int.sum, 'w.start, 'w.end,
              countDistinct('long))

    val results = windowedTable.toAppendStream[Row]
    results.addSink(new StreamITCase.StringSink[Row])
    env.execute()

    // Proctime window output uncertain results, so assert has been ignored here.
  }

  @Test
  def testInnerJoin(): Unit = {
    val ds1 = StreamTestData.getSmall3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val testOpenCall = new Func20

    val joinT = ds1.join(ds2)
      .where('b === 'e)
      .where(testOpenCall('a + 'd))
      .select('c, 'g)

    val expected = Seq("Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinWithFilter(): Unit = {
    val ds1 = StreamTestData.getSmall3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.join(ds2).where('b === 'e && 'b < 2).select('c, 'g)

    val expected = Seq("Hi,Hallo")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinWithJoinFilter(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.join(ds2).where('b === 'e && 'a < 6).select('c, 'g)

    val expected = Seq(
      "Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt",
      "Hello world, how are you?,Hallo Welt wie", "I am fine.,Hallo Welt wie")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinWithNonEquiJoinPredicate(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.join(ds2).where('b === 'e && 'a < 6 && 'h < 'b).select('c, 'g)

    val expected = Seq("Hello world, how are you?,Hallo Welt wie", "I am fine.,Hallo Welt wie")

    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinWithMultipleKeys(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.join(ds2).filter('a === 'd && 'b === 'h).select('c, 'g)

    val expected = Seq(
      "Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt wie gehts?", "Hello world,ABC",
      "I am fine.,HIJ", "I am fine.,IJK")

    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinWithAggregation(): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val settings = EnvironmentSettings.newInstance().useOldPlanner().build()
    val tEnv = StreamTableEnvironment.create(env, settings)
    env.setParallelism(1)
    env.setStateBackend(getStateBackend)

    val ds1 = StreamTestData.getSmall3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.join(ds2).where('a === 'd).select('g.count)

    val expected = Seq("6")

    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinWithGroupedAggregation(): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val settings = EnvironmentSettings.newInstance().useOldPlanner().build()
    val tEnv = StreamTableEnvironment.create(env, settings)
    env.setParallelism(1)
    env.setStateBackend(getStateBackend)

    val ds1 = StreamTestData.getSmall3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.join(ds2)
      .where('a === 'd)
      .groupBy('a, 'd)
      .select('b.sum, 'g.count)

    val expected = Seq("6,3", "4,2", "1,1")

    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinPushThroughJoin(): Unit = {
    val ds1 = StreamTestData.getSmall3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
    val ds3 = StreamTestData.getSmall3TupleDataStream(env).toTable(tEnv, 'j, 'k, 'l)

    val joinT = ds1.join(ds2)
      .where(true)
      .join(ds3)
      .where('a === 'd && 'e === 'k)
      .select('a, 'f, 'l)

    val expected = Seq("2,1,Hello", "2,1,Hello world", "1,0,Hi")

    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinWithDisjunctivePred(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.join(ds2).filter('a === 'd && ('b === 'e || 'b === 'e - 10)).select('c, 'g)

    val expected = Seq("Hi,Hallo", "Hello,Hallo Welt", "I am fine.,IJK")

    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testInnerJoinWithExpressionPreds(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.join(ds2).filter('b === 'h + 1 && 'a - 1 === 'd + 2).select('c, 'g)

    val expected = Seq("I am fine.,Hallo Welt", "Luke Skywalker,Hallo Welt wie gehts?",
      "Luke Skywalker,ABC", "Comment#2,HIJ", "Comment#2,IJK")

    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testLeftJoinWithMultipleKeys(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
      .select(('a === 21) ? (nullOf(Types.INT), 'a) as 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
      .select(('e === 15) ? (nullOf(Types.INT), 'd) as 'd,  'e, 'f, 'g, 'h)

    val joinT = ds1.leftOuterJoin(ds2, 'a === 'd && 'b === 'h).select('c, 'g)

    val expected = Seq(
      "Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt wie gehts?", "Hello world,ABC",
      "Hello world, how are you?,null", "I am fine.,HIJ",
      "I am fine.,IJK", "Luke Skywalker,null", "Comment#1,null", "Comment#2,null",
      "Comment#3,null", "Comment#4,null", "Comment#5,null", "Comment#6,null",
      "Comment#7,null", "Comment#8,null", "Comment#9,null", "Comment#10,null",
      "Comment#11,null", "Comment#12,null", "Comment#13,null", "Comment#14,null",
      "Comment#15,null")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testLeftJoinWithNonEquiJoinPred(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.leftOuterJoin(ds2, 'a === 'd && 'b <= 'h).select('c, 'g)

    val expected = Seq(
      "Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt wie gehts?", "Hello world,ABC",
      "Hello world,BCD", "I am fine.,HIJ", "I am fine.,IJK",
      "Hello world, how are you?,null", "Luke Skywalker,null", "Comment#1,null", "Comment#2,null",
      "Comment#3,null", "Comment#4,null", "Comment#5,null", "Comment#6,null", "Comment#7,null",
      "Comment#8,null", "Comment#9,null", "Comment#10,null", "Comment#11,null", "Comment#12,null",
      "Comment#13,null", "Comment#14,null", "Comment#15,null")

    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testLeftJoinWithLeftLocalPred(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.leftOuterJoin(ds2, 'a === 'd && 'b === 2).select('c, 'g)

    val expected = Seq(
      "Hello,Hallo Welt", "Hello,Hallo Welt wie",
      "Hello world,Hallo Welt wie gehts?", "Hello world,ABC", "Hello world,BCD",
      "Hi,null", "Hello world, how are you?,null", "I am fine.,null", "Luke Skywalker,null",
      "Comment#1,null", "Comment#2,null", "Comment#3,null", "Comment#4,null", "Comment#5,null",
      "Comment#6,null", "Comment#7,null", "Comment#8,null", "Comment#9,null", "Comment#10,null",
      "Comment#11,null", "Comment#12,null", "Comment#13,null", "Comment#14,null", "Comment#15,null")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testLeftJoinWithRetractionInput(): Unit = {
    val ds1 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
    val ds2 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val leftT = ds1.groupBy('e).select('e, 'd.count as 'd)
    val rightT = ds2.groupBy('b).select('b, 'a.count as 'a)

    val joinT = leftT.leftOuterJoin(rightT, 'b === 'e).select('e, 'd, 'a)
    val expected = Seq(
      "1,1,1", "2,1,2", "3,1,3", "4,1,4", "5,1,5", "6,1,6", "7,1,null", "8,1,null", "9,1,null",
      "10,1,null", "11,1,null", "12,1,null", "13,1,null", "14,1,null", "15,1,null")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testRightJoinWithMultipleKeys(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.rightOuterJoin(ds2, 'a === 'd && 'b === 'h).select('c, 'g)

    val expected = Seq(
      "Hi,Hallo", "Hello,Hallo Welt", "null,Hallo Welt wie",
      "Hello world,Hallo Welt wie gehts?", "Hello world,ABC", "null,BCD", "null,CDE",
      "null,DEF", "null,EFG", "null,FGH", "null,GHI", "I am fine.,HIJ",
      "I am fine.,IJK", "null,JKL", "null,KLM")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testRightJoinWithNonEquiJoinPred(): Unit = {
    val ds2 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds1 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.rightOuterJoin(ds2, 'a === 'd && 'b <= 'h).select('c, 'g)

    val expected = Seq(
      "Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt wie gehts?", "Hello world,ABC",
      "Hello world,BCD", "I am fine.,HIJ", "I am fine.,IJK",
      "Hello world, how are you?,null", "Luke Skywalker,null", "Comment#1,null", "Comment#2,null",
      "Comment#3,null", "Comment#4,null", "Comment#5,null", "Comment#6,null", "Comment#7,null",
      "Comment#8,null", "Comment#9,null", "Comment#10,null", "Comment#11,null", "Comment#12,null",
      "Comment#13,null", "Comment#14,null", "Comment#15,null")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testRightJoinWithLeftLocalPred(): Unit = {
    val ds2 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds1 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.rightOuterJoin(ds2, 'a === 'd && 'b === 2).select('c, 'g)

    val expected = Seq(
      "Hello,Hallo Welt", "Hello,Hallo Welt wie",
      "Hello world,Hallo Welt wie gehts?", "Hello world,ABC", "Hello world,BCD",
      "Hi,null", "Hello world, how are you?,null", "I am fine.,null", "Luke Skywalker,null",
      "Comment#1,null", "Comment#2,null", "Comment#3,null", "Comment#4,null", "Comment#5,null",
      "Comment#6,null", "Comment#7,null", "Comment#8,null", "Comment#9,null", "Comment#10,null",
      "Comment#11,null", "Comment#12,null", "Comment#13,null", "Comment#14,null", "Comment#15,null")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testFullOuterJoinWithMultipleKeys(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.fullOuterJoin(ds2, 'a === 'd && 'b === 'h).select('c, 'g)

    val expected = Seq(
      "Hi,Hallo", "Hello,Hallo Welt", "null,Hallo Welt wie",
      "Hello world,Hallo Welt wie gehts?", "Hello world,ABC", "null,BCD", "null,CDE",
      "null,DEF", "null,EFG", "null,FGH", "null,GHI", "I am fine.,HIJ",
      "I am fine.,IJK", "null,JKL", "null,KLM", "Luke Skywalker,null",
      "Comment#1,null", "Comment#2,null", "Comment#3,null", "Comment#4,null",
      "Comment#5,null", "Comment#6,null", "Comment#7,null", "Comment#8,null",
      "Comment#9,null", "Comment#10,null", "Comment#11,null", "Comment#12,null",
      "Comment#13,null", "Comment#14,null", "Comment#15,null",
      "Hello world, how are you?,null")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testFullJoinWithNonEquiJoinPred(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.fullOuterJoin(ds2, 'a === 'd && 'b <= 'h).select('c, 'g)

    val expected = Seq(
      // join matches
      "Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt wie gehts?", "Hello world,ABC",
      "Hello world,BCD", "I am fine.,HIJ", "I am fine.,IJK",
      // preserved left
      "Hello world, how are you?,null", "Luke Skywalker,null", "Comment#1,null", "Comment#2,null",
      "Comment#3,null", "Comment#4,null", "Comment#5,null", "Comment#6,null", "Comment#7,null",
      "Comment#8,null", "Comment#9,null", "Comment#10,null", "Comment#11,null", "Comment#12,null",
      "Comment#13,null", "Comment#14,null", "Comment#15,null",
      // preserved right
      "null,Hallo Welt wie", "null,CDE", "null,DEF", "null,EFG", "null,FGH", "null,GHI", "null,JKL",
      "null,KLM")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }

  @Test
  def testFullJoinWithLeftLocalPred(): Unit = {
    val ds1 = StreamTestData.get3TupleDataStream(env).toTable(tEnv, 'a, 'b, 'c)
    val ds2 = StreamTestData.get5TupleDataStream(env).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)

    val joinT = ds1.fullOuterJoin(ds2, 'a === 'd && 'b >= 2 && 'h === 1).select('c, 'g)

    val expected = Seq(
      // join matches
      "Hello,Hallo Welt wie", "Hello world, how are you?,DEF", "Hello world, how are you?,EFG",
      "I am fine.,GHI",
      // preserved left
      "Hi,null", "Hello world,null", "Luke Skywalker,null",
      "Comment#1,null", "Comment#2,null", "Comment#3,null", "Comment#4,null", "Comment#5,null",
      "Comment#6,null", "Comment#7,null", "Comment#8,null", "Comment#9,null", "Comment#10,null",
      "Comment#11,null", "Comment#12,null", "Comment#13,null", "Comment#14,null", "Comment#15,null",
      // preserved right
      "null,Hallo", "null,Hallo Welt", "null,Hallo Welt wie gehts?", "null,ABC", "null,BCD",
      "null,CDE", "null,FGH", "null,HIJ", "null,IJK", "null,JKL", "null,KLM")
    val results = joinT.toRetractStream[Row]
    results.addSink(new StreamITCase.RetractingSink)
    env.execute()
    assertEquals(expected.sorted, StreamITCase.retractedResults.sorted)
  }
}

redpajama_set_name: RedPajamaGithub


Making a telecommunication network diagram involves many specific elements of telecommunication technology that can be managed using ConceptDraw DIAGRAM. The ability to design telecommunication network diagrams quickly and easily contains in the Telecommunication Networks Diagrams solution. The telecom network diagram may be the part of the network documentation that should be presented as MS Word document. In this case, the best way is using the advanced copy-and-paste functionality of ConceptDraw DIAGRAM.
Result: You can easily supplement any MS Word document with diagrams.


Video by Giles Hendrix and Joshua Goldberg at New York's Central Park performing live for Paul van Dyk and Made Events. Check out the show flyer on view at the Made Event archive. View the Flickr slideshow of our photos. And check out all the YouTube videos from the crowd of all our Central Park PvD gigs.
You are currently browsing the GESTUREMEDIA.tv weblog archives for August, 2005.


text:
U.S.|Despite Similar Shooting, Los Angeles's 'Bank of Trust' Tempers Reaction
Despite Similar Shooting, Los Angeles's 'Bank of Trust' Tempers Reaction
The site where Ezell Ford, 25, was shot and killed by Los Angeles police on Aug. 11, two days after the police shooting of Michael Brown in Ferguson, Mo.CreditCreditMonica Almeida/The New York Times
By Jennifer Medina
LOS ANGELES — When Los Angeles police officers shot and killed Ezell Ford, an unarmed 25-year-old black man last week, it took less than 24 hours for Lita Herron to get a phone call from a ranking officer at a nearby station.
"They wanted to check in and gauge our rage," said Ms. Herron, a grandmother and organizer who has worked to prevent gang violence on the streets of South Los Angeles for years. "They wanted to ask us to quell rumors and hear what we need. We've all been through this before — even when we know things are wrong, we aren't looking for things to explode."
In Ferguson, Mo., however, angry protests stretched on for nearly two weeks after the police killing of Michael Brown in circumstances that were strikingly similar: an unarmed young black man shot by the police, who some witnesses say was not putting up a struggle.
The killings occurred two days apart. The protests in Missouri were driven initially, in large part, by the police's refusal to release the name of the officer involved or details of the Aug. 9 shooting. Here, the police are still holding back the autopsy report and the names of the officers involved, citing security concerns.
Yet the reaction in Los Angeles, where clashes between the police and residents have a long history, has so far been much calmer.
While there have been several protests since the Aug. 11 shooting of Mr. Ford, who was mentally ill, including an impromptu march that blocked traffic on city streets, the police have maintained a relatively low profile, relying primarily on a handful of bicycle-riding officers in polo shirts rather than the rifle-carrying officers in riot gear pictured in Ferguson. This week, Chief Charlie Beck and other top-ranking officials showed up for a community meeting at a local church, telling the angry crowd of several hundred that there were still more questions than answers about the shooting.
In the more than two decades since riots erupted after white police officers were acquitted in the beating of Rodney G. King, a black construction worker, relations between law enforcement and their communities here have changed drastically. In many South Los Angeles police precincts, officers routinely check in with organizers like Ms. Herron. Local church leaders have officers' phone numbers committed to memory. When protests are planned, seasoned organizers let the police know — even when the police are the target of their outrage.
"We have an infrastructure here where there are outlets for people to vent frustration and move into action," said Marqueece Harris-Dawson, the president of Community Coalition, which runs several programs for residents in South Los Angeles. "This has taken more than 20 years to build and sustain — there's no question it would not have been this way a generation or two ago."
Still, on the streets of South Los Angeles, a predominantly black and Latino neighborhood, a sense of distrust of the police remains. Mr. Harris-Dawson, who is black, often points out that he has had a gun pointed at him by an L.A.P.D. officer four times and has never carried a weapon. Black and Latino teenage boys rattle off instances where they were pulled over and questioned for what they say was no reason. Still, many local leaders are willing to give the department some leeway to continue the investigation into the Ford shooting before coming to a clear conclusion.
There have been protests in Los Angeles, but they have been much less violent.CreditMonica Almeida/The New York Times
"The chief also does not make it the job of the department to exonerate the officer," Mr. Harris-Dawson said. "They do take a minute to have some remorse for the fact that someone is dead."
When Earl Ofari Hutchinson, a longtime civil rights leader here and a frequent critic of the department, demanded a meeting with top police officials last week, they quickly arranged to discuss the case. They listened to Mr. Hutchinson's demands for a "fast track" investigation and a quick release of the officers' names and the autopsy results. Earl Paysinger, an assistant police chief, declined to predict when such information would be available, saying detectives were still canvassing the area looking for witnesses.
Chief Paysinger said in an interview on Friday that the department was "well aware we can't let it go on indefinitely."
"We've seen this film before — this is 'Groundhog Day' for us," Chief Paysinger said. "What the people are demanding is not unreasonable. We know that whatever we say first will become gospel, and we'd rather deal with some discontent now than putting out information we have to correct later."
Mr. Paysinger, who has been with the department for nearly 40 years and oversees its day-to-day operations, said that the department had for years now tried to rely on what it called the "bank of trust" among community members. Just more than a year ago, the department was under a consent decree imposed by the Justice Department, after dozens of officers were accused of tampering with evidence and physically abusing and framing suspects.
"We've learned that community outreach can't wait for the day when you're in trouble and need help," Chief Paysinger said. Now, he said, the network of community support is so wide, it is a matter of course for officers to call local leaders routinely. And the efforts have expanded along with the importance of social media: Each police station now assigns personnel to monitor websites, Facebook and Twitter almost round-the-clock, watching for everything from signs of gang activity to how people are reacting to political events.
In some sense, Mr. Ford's death is remarkable for the publicity it has received here — several longtime activists said it would be easy to imagine the shooting getting little attention were it not for the outrage in Missouri.
Officers here have shot and killed 12 people so far this year, compared with 14 such deaths all of last year. In several protests after the Ford shooting, one organization held up a large banner listing the names of more than 300 people who have died during conflicts with law enforcement here in the last seven years.
"This happened just as it became clear that Ferguson was a billboard of what we did not want to do," said Curren Price, a city councilman who represents South Los Angeles and organized the community meeting this week, which was attended by the police chief, as well as the head of the police oversight board. "We all knew this is another critical juncture for us."
"There are a lot of deep wounds — L.A.P.D. was a pretty notorious organization not that long ago," Mr. Price said. "Unfortunately, anytime something like this happens, it brings all that back to the surface. There's still a long way to go before we can say things are good."
A version of this article appears in print on , Section A, Page 14 of the New York edition with the headline: Despite Similar Shooting, Los Angeles's 'Bank of Trust' Tempers Reaction. Order Reprints | Today's Paper | Subscribe
Key Factor in Police Shootings: 'Reasonable Fear'
As Law Enforcement Presence Eases, 'Small Gains' Are Noted in Ferguson
Outcry and Confrontation in Ferguson

redpajama_set_name: RedPajamaCommonCrawl


text:
Bill S.2099 191st (2019 - 2020)
An Act to authorize Massachusetts Fallen Firefighter Memorial motorcycle license plates
By Mr. Hinds, a petition (accompanied by bill, Senate, No. 2099) of Adam G. Hinds, Michael D. Brady, Anne M. Gobi, Patrick M. O'Connor and other members of the General Court for legislation to authorize Massachusetts Fallen Firefighter Memorial motorcycle license plates . Transportation.
Adam G. Hinds
Referred to Senate Committee on Ways and Means
1/22/2019 Senate Referred to the committee on Transportation
5/9/2019 Joint Hearing scheduled for 05/14/2019 from 10:00 AM-12:00 PM in B-2
3/12/2020 Senate Bill reported favorably by committee and referred to the committee on Senate Ways and Means
An Act establishing special license plates in support of Massachusetts law enforcement
An Act relative to license plates for disabled veterans
An Act relative to license plate year of manufacture registration
An Act relative to special veterans plates.


text:
openSecurity
PKK take steps to bolster Turkish reforms
PKK members surrender to Turkey to back peace reforms. Roy Bennett trial threatens Zimbabwe unity government. Top Islamabad University bombed whilst Pakistan Taliban captures ground. U.S. offers new approach towards Sudan and more in today's Security Briefing.
Geraint Rees
A group of Kurdish separatist fighters and supporters surrendered themselves to the Turkish army on Monday in a gesture of rebel support for government plans to expand Kurdish rights.
The group, which consisted of eight fighters from the Kurdistan Workers Party (PKK) and twenty-six Kurdish refugees, were cheered on by thousands of supporters waving PKK flags as they crossed the Silopi border from Iraq and gave themselves in to the waiting Turkish army. The group were received by a Turkish judge and five prosecutors who will determine whether its members had committed any crimes.
Keep up to date with the latest developments and sharpest perspectives in a world of strife and struggle. Sign up to receive toD's daily security briefings via email by clicking here
The symbolic step by the PKK was initiated by Abdullah Ocalan, the group's jailed leader, and is largely seen as backing for a Turkish initiative that is expected to give greater freedoms to the twelve million-strong Kurdish minority. The plan was launched by Turkish Prime Minister Tayyip Erdogan's Justice and Development (AK) Party in August this year but has faced resistance from Turkish nationalist and other opposition parties which perceive the plan as conceding to terrorists. The PKK formed twenty-five years ago to secure Kurdish autonomy in southeast Turkey. The resulting conflict has left more than 45,000 people dead.
The ToD verdict: The PKK announced on Sunday that some of its members would return to Turkey in 'a move designed to give a chance to peace and to pave the way for democratic politics'. Their return was met by thousands of supporters in the border town of Silopi and supporter rallies across Turkey, indicative that this small gesture signals a historic shift.
After 25 years of violent struggle, the motivation behind the PKK's 'insistence on peace not war' could lie in the changing attitudes of Kurds towards engagement with Turkey, and the wider international community.
Ethnic Kurds have been striving for recognition of the Kurdish identity and the establishment of an independent Kurdish state since 1922, when the Treaty of Lausanne carved up Kurdish dominated regions into what are now modern Turkey, Iran, Syria and Iraq. Given this geographic spread, the realisation of a 'Greater Kurdistan' would involve the break up of four different states, an idea that many in the international community baulk at given the geopolitical importance of the region, and would pose further problems regarding the fate of the Iraqi, Turkish, Iranian and Syrian minorities living in these areas. For these reasons, amongst others, the ideal of independence has largely been dropped by Kurdish groups in the different partition areas, and many now pursue greater recognition and autonomy within the framework of their host state.
In Turkey, the PKK has reduced its main political goals of independence to demands for constitutional recognition of Kurdish language and culture, civil rights and some level of autonomy for Kurdish people living in Turkey. Despite the dilution of its goal, meeting these demands would involve altering the Turkish constitution to give greater rights to Kurdish people, an act which Turkey has traditionally rejected. The resistance to granting some broader cultural and political rights to Kurds by Turkish opposition parties is testament that the group's use of violence over twenty-five years has endangered the possibility of peaceful cohabitation in the same political space.
The PKK's change in tactics may have been inspired by watching the emergence and eventual legalisation of the Kurdistan Regional Government in northern Iraq. Negotiation and Kurdish participation in the Baghdad government has brought the consolidation of the Iraqi Kurdistan Region which, although far from an independent state, has given Iraqi Kurds the ability to shape their political future in a significant way and reinvigorated Kurdish aspirations in the wider region. According to broadcaster CNN Turk, the PKK group delivered a letter which stated 'it has become abundantly clear to both Turks and Kurds that problems will not be resolved with violence and the solution requires political democracy'. The letter could be referring to the Road Map to peace, launched in August by PKK leader Abdullah Ocalan. The plan outlines the PKK's goals for Kurdish civil rights in Turkey, and offers suggestions of how Turkey could take the lead in solving the Kurdish issue regionally. Crucially, the plan outlines the steps which would lead to the eventual disarmament of the rebel group.
Turkish moves following the surrender of the group will be watched closely - both by Kurdish groups and the members of the European Union. Kurdish groups may fear a repeat of 1999, when the PKK sent two groups of fighters to Turkey on a similar peace initiative, who were arrested and jailed for belonging to the organisation. Splinter Kurdish movements have denounced the peace initiatives of the PKK and remain committed to violent separatism. EU leaders will look for evidence of a genuine shift in Turkish treatment of the rebels, as greater freedoms and protection of Kurdish minorities is seen as vital if Turkey is to meet the bloc's human-rights criteria for membership.
Terror trial of Tsvangirai aide threatens government unity
The arrest of a senior aide to Zimbabwe's prime minister, Morgan Tsvangirai, has caused a huge rift which threatens Zimbabwe's fragile unity government. Roy Bennett, the treasurer of Tsvangirai's Movement for Democratic Change, was arrested on his return to Zimbabwe from South Africa in February. He was charged with illegal possession of arms to commit terrorism and banditry and later released on bail. Bennett's was arrested again last week prompting Tsvangirai to threaten his party's disengagement from the unity cabinet he shares with the ZANU-PF party, headed by President Robert Mugabe, calling the party 'dishonest and unreliable'. Bennett is due to stand trial for terrorism, which carries a maximum death sentence on conviction, on 9 November. Zimbabwean President Robert Mugabe has refused to swear Bennett into the unity government until he is acquitted.
Top Islamabad university bombed whilst Pakistan Taliban captures ground
Two suicide bomb blasts at an Islamic university in Pakistan's capital city have killed six people and wounded at least twenty today. The attacks took place early on Tuesday afternoon and hit the women's cafeteria and the Islamic law department. Although no group has yet claimed responsibility, the attacks are the first since the Pakistani army began its offensive against militants in South Waziristan and suspicion falls on Taliban militants in the area. The battle between Pakistan and Taliban militants in the country's north-eastern region raged on today, with reports that militants re-took Kotkai, a small but strategic town on the approach to an insurgent base which had been captured by the army on Monday. More than 20,000 civilians have fled South Waziristan since the beginning of the offensive according to UN reports.
US offers new approach towards Sudan
The US will seek to renew economic sanctions on Sudan, but also promised broad engagement with Khartoum in an effort to end violence in Darfur and the semi-autonomous south. President Barack Obama stated that if Sudan acted to improve the situation on the ground, the US could offer incentives ahead of crucial polls next year. Although the form of the promised incentives remained classified, Secretary of State Hillary Clinton outlined the US goals to end war crimes and other violence in Darfur, ensure implementation of a fraying 2005 peace deal between the Khartoum government and former southern rebels, and to prevent Sudan from becoming a haven for international terror groups. An estimated 300,000 people have been killed in the Sudanese conflict since 2003, many at the hand of government-backed militias.
Democracy and government


text:
Ecotourism in Costa Rica takes center stage in the July Howler, with a cover story that explores the meaning of this sometimes misunderstood word, along with its next of kin, sustainable tourism. We profile Rafael Gallo, the pioneering founder of whitewater rafting giant Ríos Tropicales, and pay a visit to the pristine Osa Peninsula, the wildest place in Costa Rica where visitors are actually welcome. We also do a road trip in Sarapiquí, one of Costa Rica's least known greatest places, and discuss the challenges of Diamante Eco Adventure Park's efforts to win five leaves for sustainable tourism.
Carlos Hiller, a brilliant local artist who turns painting into performance art, is profiled in Arts and Entertainment, and we have selections from humor columnists Johnny Lahoud and Jesse Bishop, who are funny even when they're not trying to be. There are two "mini-mags" here, the Dining Guide and Surfing. And we have our regular columns on hot topics — fashion, Spanish, history, photography, pets, law, construction and much more.


text:
The Energy Payoff
GreenerBuilding...
With benchmarking and a long-term view on energy efficiency upgrades, USAA saves more than $1 million annually at its San Antonio headquarters. By Abigail May
Everybody loves a success story. And where facilities management is concerned, one need look no farther than San Antonio, where a large financial services company's long-term commitment to energy efficiency is reaping big rewards. In addition to delivering $1.1 million in annual savings, USAA's energy focus recently landed the company a 2003 Energy Star® award for its San Antonio global headquarters — the second-largest privately owned building in the nation and the largest structure ever to receive Energy Star best-in-class status.
USAA's energy accomplishments make for a facility management success story, to be sure. But they also offer a useful case study that illustrates many lessons of Facility Management 101: The benefits of taking the long view on energy upgrades; the value of benchmarking; the importance of open communication with senior management and of multilevel buy-in; and the rewards of doing the right thing where energy is concerned.
USAA's pursuit of Energy Star accolades did not begin with the 4.6-million-square-foot San Antonio headquarters building, which is home to some 15,000 USAA employees. It began with Brenna Walraven. As executive director of property management for USAA's subsidiary, USAA Real Estate Co., Walraven oversees a portfolio of 35 investment properties across the country. A long-time believer in the importance of energy efficiency, Walraven approached her supervisors about her desire to pursue Energy Star labeling across the investment portfolio in 2000.
Working in concert with USAA Real Estate Co.'s engineering contractor, and with support from Energy Star, Walraven and her associates began benchmarking all facilities under their management using Energy Star's online tools. Walraven's staff received training in the use of the Portfolio Manager tool and began aggressively pursuing the opportunities for efficiency gains identified within their buildings. Monthly reports from engineers included specific updates on Energy Star progress and activities, and the effort became a primary focus for Walraven's team.
Three years later, roughly 40 percent of the buildings in USAA Real Estate Co.'s portfolio have now achieved the score of 75 that is necessary to earn an Energy Star label. And, while not every facility in the portfolio can expect to ever achieve designation as a "best in class" energy performer — occupancy and usage considerations knock some out of the running — USAA Real Estate Co.'s overall efforts garnered Energy Star's Partner of the Year award for 2002. What's more, the cost-saving and marketing benefits of the initiative have made Energy Star believers out of management at all levels.
Executives in USAA's corporate division were among those paying attention. Following the lead of its subsidiary, USAA began pursuing Energy Star designation for its San Antonio headquarters building — one of roughly 10 corporate-occupied facilities across the country — early this year. A few months later, an Energy Star plaque was hanging in that facility's lobby — a validation, executives say, of the company's long-term focus on energy.
With a monthly energy bill that routinely exceeds $500,000, it's not hard to see why bottom-line savings was a major incentive for USAA to pursue energy-efficiency upgrades in its headquarters building. Indeed, the facility's energy improvements — many of them made years before Energy Star labeling became a goal—have yielded tangible results. For example, a $900,000 retrofit of 18,000 fluorescent fixtures from T-12 lamps with magnetic ballasts to T-8 lamps with electronic ballasts yields annual energy savings of $110,000 and operation and maintenance savings of $137,000. Shutting off the escalators after hours saves 1.1 million kilowatt-hours a year, saving $46,000. Reducing light levels in parking garages in the after-hours saves 1.3 million kwh, or $56,000, per year.
But since the late 1980s, when USAA began making energy-efficiency improvements to the early-'70s-era facility, the incentive has been more than just financial.
"Through the years we have focused on providing a world-class work environment for our employees, which means periodically upgrading," says Howard Gelfer, vice president of facilities management for USAA. "We have adopted an energy focus both because it is good for the bottom line and because it is the right thing to do."
Thanks to that long-term philosophy, the process of earning Energy Star labeling for the San Antonio facility was not a difficult one. Despite its size, huge data center, and high energy-consuming amenities like fitness centers and cafeterias, the building simply did not have far to go. At the same time, however, it had less to gain financially from the Energy Star process than many other facilities would.
"In that region of the country, the kilowatt-hour rate is around 7 cents," says Stuart Brodsky, program manager for Energy Star's commercial property markets. "That means they were looking at some longer payback periods because their energy costs overall were already relatively low. The fact that they still pursued and are continuing to pursue additional improvements indicates to me that the commitment is both fundamental and well communicated. They look for both payback and the broader environmental opportunity."
USAA Real Estate Co. has also reaped significant bottom-line benefits, above and beyond its energy savings, as a result of the marketing edge provided by its energy commitment and, specifically, its Energy Star successes. Walraven says she believes the organization gains an important edge when tenants, particularly in tough energy markets like California's, start asking pointed questions.
"The label helps to set their organization apart to financial communities," says Energy Star's Jean Lupinacci. "They can say, 'We are good at management; we soundly manage our resources, we are not wasting.' For some audiences that is a very important message, and it's one they can send to both employees and tenants."
By all accounts, USAA's success in pursing Energy Star "best in class" status has come as a result of both this long-standing commitment to energy efficiency and of exemplary teamwork between USAA's facility executives and the organization's top management.
"USAA's commitment went all the way through the organization chart, so it wasn't surprising to see the building score as well as it did," says Brodsky. "They have a truly integrated approach. As a rule, all of the organizations that are excelling in energy management have integrated approaches where there are cross-departmental energy teams, and where people at every administrative level have energy efficiency as a specific part of their job description."
"Good facility management and energy conservation translate to good business in general," says USAA's Gelfer. "We have been fortunate enough to have leadership that recognizes that."
Which is not to say that facility executives have not faced challenges in convincing top management of the wisdom of some investments.
"In today's environment you look at these projects in terms of the benefits but also the impact of the costs," says Wayne Peacock, senior vice president of corporate real estate. "We have had to demonstrate payback in very concrete terms, and we have really been put through the paces on some of these decisions."
Further highlighting the integrated mindset that has set USAA apart as a top energy performer, Peacock says, "We look at that return both in terms of cash savings and in terms of benefits to the employees."
Benchmarking is Key
Within USAA's corporate real estate division and for subsidiary USAA Real Estate Co., energy efficiency is, increasingly, a way of life. This reality was underscored, though certainly not created, by the Energy Star process over the past several years.
"The lesson in this story," says Energy Star's Brodsky, "is not that USAA had a complex building and found that they were able to make it energy efficient. The interesting thing from my perspective is that they want to make it more efficient. They want to benchmark the building next year and have a score that is better than this year's."
Toward that end, USAA's corporate real estate division is moving to the next step by looking at opportunities to further trim energy usage. One possibility: integrating the operations of the San Antonio facility's two mechanical plants so that they can effectively take turns servicing the campus rather than operating both plants at all times.
The same attitude prevails across USAA Real Estate Co., where Walraven has found that the ability to benchmark against other facilities is key to ongoing improvements.
She says a commitment to benchmarking is one of the key lasting outcomes of the Energy Star process. Constant evaluation of all facilities' performance and identification of ways to boost efficiency even incrementally form a backbone of efforts to further boost the efficiency of the entire portfolio.
"When you go from zero to say 80 percent, that's great," says Walraven. "But to go from 80 to 95 percent is hard. There is no more low-hanging fruit. That is certainly our challenge going forward."
Abigail May is a freelance writer in Philadelphia who specializes in writing about facilities.
USAA's success in Energy Star is the result of a long-term focus on energy, not of any one retrofit. The following are some of the specific energy-savings steps the organization has implemented to help its global headquarters building achieve and maintain best-in-class energy performance:
Kilowatt usage throughout the facility is monitored routinely.
Lighting systems use energy-efficient lamps and ballasts.
Energy management and control systems monitor air conditioning and lights.
SCADA monitors and controls electrical distribution systems.
Motion sensors control lighting in conference rooms and offices.
Escalators are shut down when not in use.
Washing machines in the fitness center are high-efficiency.
Chilled water in the cooling system is maintained at a slightly higher temperature.
Motors in pumps and air handling units use variable frequency drives.
This article first appeared in July 2003 issue of Building Operating Management.
USAA Real Estate to Reduce its Portfolio Energy Use 30 Percent by 2012
ByGreenerBuilding...
Kodak, 3M Among 50 to Win EPA Nods for Energy Efficiency, GHG Reductions
JLL Enrolls Entire U.S. Property Management Portfolio in Energy Star Program
Energy Star Buildings Chalk Up a Decade of Savings
Powering Profits: How Companies Turn Energy Efficiency into Shareholder Value
ByEmily Rabin
Turning Title 24 Regulations into Smart Savings
Unlocking ROI+: Understanding the Complete Return on Smart Building Investments


Known as carbon activation, the conversion of carbon dioxide and methane into useful compounds like fuels or polymers has long been a goal of the chemical industry. Both compounds are in ready supply, and both are potent greenhouse gases contributing to climate change — methane having a far more potent greenhouse potential than CO2 — but both are extremely stable and therefore difficult to persuade to react without using high temperatures and pressures — themselves difficult to achieve without using more energy.
Methane activation could replace wasteful flaring in oil extraction, converting the gas into useful liquid products.
The Liverpool team, led by electrical engineer Xin Tu, has devised a process that converts a mixture of methane and CO2 to acetic acid in a single step. Taking place at room temperature and atmospheric pressure, the process involves a non-thermal plasma — an electrically-charged gas mixture — to use the methane as a source of hydrogen. In a paper in the journal Angewandte Chemie, the team says that this reaction is almost impossible to achieve by heating the gas mixture, even using a catalyst, because the thermodynamic barrier is so high.
In a non-thermal plasma, the gas temperature remains low but electrons are highly energetic. The team devised a plasma reactor, consisting of two concentric glass tubes, the inner of which was lined with a stainless steel electrode; the space between the two tubes was filled with water which served two purposes — acting as a ground electrode and removing heat from the system as the mixture of methane and CO2 was pumped through the inner cylinder and a voltage applied to the steel electrode to create the electrical discharge to generate a plasma, which flowed through a platinum, gold or copper catalyst, supported on pellets of porous aluminium oxide material which was packed into the inner tube.
An advantage of plasma systems is that they can easily be scaled up, and are easier than thermal processes to start up and shut down, as they reach a steady state quickly and have fast reaction rates. This means that they use less energy than thermal processes, and can potentially be powered by renewable sources like solar or wind, with the compounds formed acting effectively as a type of chemical energy storage.
"This is a major breakthrough technology that has great potential to deliver a step-change in future methane activation, CO2 conversion and utilisation and chemical energy storage, which is also of huge relevance to the energy & chemical industry and could help to tackle the challenges of global warming and greenhouse gas effect," Tu said.
One particular application could be to replace the flaring of excess methane from oil wells, instead converting the methane into useful liquid fuels or chemical that can be easily stored or transported.
Appears a great idea and I hope it can be scaled up as claimed. My concern is catalyst poisoning owing to the ionic discharge.
Truly, the natural gas would have to be scrubbed (most likely) to remove any H2S upstream.
The alternative is that a cold plasma may behave differently to sulfur compounds than would a thermal process.
Tunability of this process has yet to be explored in depth, it appears, but would be most interesting if other chemical intermediates can be thusly produced.


text:
Pyrolysis of paper sludge and utilization for ionic dye adsorption
Hu, S.-H., and Hu, S.-C. (2013). "Pyrolysis of paper sludge and utilization for ionic dye adsorption," BioRes. 8(1), 1028-1042.
Paper sludge was pyrolyzed to synthesize an adsorbent for ionic dyes. Two reagents, Methylene Blue (MB) and Procion Red MX-5B (PR), were chosen as adsorbates. Pyrolysis of paper sludge was conducted at 600°C for 1 h under a nitrogen atmosphere, and the carbonized sample was washed with 1 M HCl for 30 min to remove inorganic salts (such as calcium) and to increase the carbon content. Scanning electron microscope (SEM) imaging showed that the particle size of the pyrolyzed paper sludge was obviously reduced when the acid-washing process was applied. Additionally, the specific surface area had increased from 13.25 to 193.86 m2/g. The isoelectric point was around pH 3, which meant the adsorbent revealed positive charge to adsorb anionic dye (PR) when pH was below 3. On the other hand, cationic dye (MB) was adsorbed well under high pH values because of the negative surface charge of the adsorbent. The Langmuir equation was adopted to determine maximum absorption capacity. For MB and PR, the maximum absorption capacities were 119.05 mg/g and 65.79 mg/g, respectively. The adsorption kinetic study revealed that MB and PR adsorptions fit the pseudo-second-order kinetic model well. The activation energies for MB and PR were 12.32 kJ/mol and 2.88 kJ/mol, respectively. The results presented indicate that paper sludge can be pyrolyzed to form a dye adsorbent for cationic and anionic dyes.
Shao-Hua Hu,a,* and Shen-Chih Hu b
Keywords: Paper sludge; dye adsorption; pyrolysis; Methylene Blue; Procion Red
Contact information: a: Dept. of Environmental Resources Management, Dahan Institute of Technology, Hualian, Taiwan; b: Dept. of Material Science and Engineering, National Dong Hwa University, Hualian, Taiwan; *Corresponding author: shaohwa@ms01.dahan.edu.tw
Dyes can be used in many industries, such as in food, paper, textile, rubber, and plastics, in order to color products (Crini 2006; Olivella et al. 2012). After manufacturing, dyes are washed and dissolved in the wastewater. Dyes in wastewater are difficult to remove when utilizing conventional wastewater treatment methods. Dye molecules consist of two key components: 1) chromophores, which are responsible for producing color; and 2) auxochromes, which augment the chromophores, render the dye soluble in water, and enhance dye adsorption affinity toward the substrate (Gupta and Suhas 2009). Dyes are, by design, recalcitrant organic molecules that are stable when exposed to light, heat, and oxidizing agents (Sun and Yang 2003). Methods of dye removal from wastewater include coagulation, filtration, advanced oxidation processes, electrochemical methods, and adsorption (Gupta and Suhas 2009). Shi et al. (2007a) studied the removal of Direct Black 19, Direct Red 28, and Direct Blue 86 by coagulation with three different Al-based coagulants. A synthesized coagulant, designated as Al13, was produced following the method of Shi et al. (2007b), and compared with AlCl3 and polyaluminum chloride (PAC), a traditional Al-based coagulant. The results showed that the coagulation of direct dyes could be greatly affected by pH, and the coagulation efficiency order was Al13 > polyaluminum chloride > AlCl3. Kim et al. (2005) combined nano-filtration (NF) and reverse osmosis (RO) membranes to investigate the operating conditions for Reactive Yellow 145 (RY145) and Reactive Black 5 (RB5) removal. By combining NF and RO membranes, removal of chemical oxygen demand (COD) and of color were 98.4% and 99.6%, and the rejection efficiencies were 53.2% for RB5 and 96.6% for RY145. When compared to only NF membrane filtration, the removal of COD and of color were more than 96%, while the rejection efficiencies were 21.2% and 51.7% for RB5 and RY145, respectively. Lucas and Peres (2006) investigated the oxidative decolorization efficiency of RB5 in aqueous solution with Fenton and photo-Fenton processes. The optimal ratio of [H2O2]/[RB5] and [H2O2]/[Fe2+] were 4.9:1 and 9.6:1 at pH 3. The oxidative decolorizations of RB5 with Fenton and photo-Fenton processes were 97.5% and 98.1%, respectively, under optimal conditions. Total organic carbon (TOC) removal was 46.4% under the photo-Fenton process, which was higher than that of Fenton process (21.6%); the result indicates that a UV lamp has little effect on dye decolorization but is important in the reduction of TOC in dye solutions. Doğan and Türkdemir (2005) used an electro-chemical alternating treatment process of textile wastewater. The experiment was conducted using a batch-type divided electrolytic cell under constant potential with a Pt cage as anode and a Pt foil as cathode. The results showed that acidic conditions were more efficient for electrolysis. The electrolysis process achieved almost 100% color removal and 60% reduction in COD for a 0.1% (w/v) dye solution concentration at a pH 1 and with a 0.24 M of NaCl as an electrolyte for a 90 min treatment period.
Among the techniques mentioned, coagulation is a simple and economically feasible method for dye removal, but it produces a large amount of sludge, which in turn creates a disposal problem. Membrane processes require high pressure, and pores may be obstructed easily by suspended solids. Oxidation is a rapid process, but it uses chemical reagents to promote activation. It may also increase operational costs, thereby decreasing economic feasibility (Crini 2006). Among these methods, adsorption gives the best results as it can be applied to remove different types of dyes and produce high-quality treated effluent (Jain et al. 2003; Crini 2006). Rafatullah et al. (2010) even mentioned that adsorption was superior to other techniques for water re-use because of low initial cost, flexibility, simplicity of design, ease of operation, insensitivity to toxic pollutants, and no formation of harmful substances during application. Among all kinds of adsorbents, activated carbon is the most effective and the most widely used (Walker and Weatherley 1998). However, it is expensive and its regeneration by a refractory technique results in a 10 to 15% adsorbent loss, as well as a reduction of its adsorption capacity (Waranusantigul et al. 2003). Therefore, low-cost alternative adsorbents have been investigated as substitutes for activated carbon; these include abundant natural materials such as wood (Sahu et al. 2010; Khezami et al. 2007), coal (Liu et al. 2009), and agricultural wastes such as plum kernels (Tseng 2007), olive bagasse (Demiral et al. 2011), oil palm shell (Jia and Lua 2008), almond shells (Rodriguez-Reinoso et al. 1982), as well as industrial wastes such as tire rubber (Miguel et al. 2003), sewage sludge (Martin et al. 2002; Monsalvo et al. 2011), waste polyethylene terephthalate (PET) bottles (Nakagawa et al. 2004), fly ash (Mohan et al. 2002; Purnomo et al. 2012), and lignin (Hayashi et al. 2000). Importantly, for low-cost adsorbents, the manufacturing process should be as simple as possible to reduce the cost of production. Most of the references presented on this topic used activation processes to enhance the adsorption capacity of adsorbents; however, activation processes increase costs because they require somewhat expensive equipment or chemical reagents. Such processes also require further treatment of derived corrosive gas (H2SO4) or Zn-containing solutions (ZnCl2).
Paper sludge is a major waste by-product of the paper industry in Taiwan, and it contains water, fiber, organic compounds, inorganic salts, and mineral fillers (Maschio et al. 2009). It is believed that paper sludge can also be a precursor of carbonaceous adsorbents because of high organic content. In order to simplify the manufacturing process, paper sludge was pyrolyzed at 600°C for 1 h (thereafter refer to as P600) and washed with 1M HCl to become a carbonized adsorbent PC600. Both cationic (Methylene Blue, MB) and anionic (Procion Red MX-5B, PR) dyes were chosen as adsorbates in order to study the adsorption ability of PC600. Isotherm adsorption and adsorption kinetics experiments were also conducted, and Langmuir, Freundlich, and pseudo-first-order and pseudo-second-order equations were used to examine the experimental results. The maximum adsorption capacity and activated energy of adsorption were obtained, and the adsorption behavior of adsorbent derived from paper sludge toward ionic dyes was also evaluated.
Characteristics of Paper Sludge
The paper sludge utilized in this study came from a paper mill of eastern Taiwan. To understand the characteristics of the sludge, a sample was dried at 110°C and was analyzed using atomic absorption spectrometry (AAS, Varian, AA240), X-ray diffract-tometer (XRD, Rigaku), and ignition loss testing.
Chemical analysis was performed with 0.2 g of the sample mixed with 16 mL of aqua regia and 8 mL of hydrofluoric acid; this mixture was heated at 180°C for 3 h. The filtrate was diluted and analyzed using AAS. An X-ray diffractometer was used to examine and scan the crystalline phases of the dry sample from 10o to 80o (2θ) at a scan rate of 4 degrees per minute with a voltage and a current of 30 KV and 50 mA, respectively. For ignition-loss testing, 5 g of paper sludge (W1) were heated at 800°C for 3 h. The weight of the ignited residue (W2) was recorded while the sample cooled. The result of ignition loss was calculated according to Equation (1):
The Production and Characteristics of Adsorbent Derived from Paper Sludge
Dried paper sludge was placed in a crucible and heated with a tube furnace. The heating rate was 20oC/min and the nitrogen flow was 2 L/min for 5 min in advance of heating. The carbonization process was carried out at 600°C for 1 h; the resultant residual was labeled as P600. After cooling, the carbonized solid sample was mixed with 1M HCl solution (40:1 liquid to solid ratio) for 30 min. After the acid treatment, the residual was twice washed with DI water. Finally, the sample was dried at 105°C and named PC600.
X-ray diffraction (XDF) analysis, specific surface area, and zeta potential were tested to understand the characteristics of the PC600. The XRD analysis procedure was the same as that of sludge analysis. The specific surface area was measured from the N2 adsorption isotherms at 77 K (-196°C) with an adsorption apparatus (Autosorb-1, Quantachrome) and calculated utilizing the BET (Brunauer-Emmet-Teller) method (Brunauer et al. 1938). Pore size distribution was calculated using the BJH (Barrett-Joyner-Halenda) method (Barrett et al. 1951). Approximately 0.1 g of PC600 was mixed with 1000 mL of 0.001M NaCl solution to determine the zeta potential of the adsorbents by a zeta potential analyzer (Nano Z, Malvern). The particles were dispersed in an ultrasonic cleaner for 30 min, and 1M HCl or NaOH solution was used to adjust the pH within a range of 2 to 10.
Adsorption Experiment
MB and PR were chosen as adsorbates; they were cationic and anionic dyes in aqueous solution, respectively. The adsorption of dyes was studied in batch mode, and the concentration of each sample determined by UV/Vis spectrometry (Lambda 25, Perkin Elmer) at wavelengths of 664 nm for MB and 538 nm for PR. The methods used for adsorption behavior are explained in the following subsections.
Effect of pH on adsorption
Approximately 0.25 g of PC600 was added into 25 mL of dye solution, of which the initial concentrations of dye were 1200 mg/L for MB and 500 mg/L for PR. The adsorption experiments were conducted at 30°C for 2 h. After the adsorption experiments, the solution was filtered, and the concentrations of MB and PR were determined using UV/Vis spectrometry.
Chemical oxygen demand (COD) was also measured for the filtrates after adsorption according to the standard method of the National Institute of Environmental Analysis (NIEA W5.17.52B) of Taiwan. Approximately 2.5 mL of filtrate, 1.5 mL of 0.02 M K2Cr2O7, and 3 mL of Ag2SO4/H2SO4 solution were mixed and heated at 150°C for 2 hrs. After cooling, the solution was titrated with 0.25 M (NH4)2Fe(SO4)2; ferroin (1,10-phenanthroline monohydrate, C12H8N2•H2O) was used as an indicator. A blank sample was prepared by substituting 2.5 mL of the filtrate for 2.5 mL of DI water. When the color of the solution changed from yellow to red, the end point of titration was reached. The value of COD obtained from Equation (2),
where A and B were the volume (mL) of (NH4)2Fe(SO4)2consumption in the blank and sample, respectively; M was the concentration of (NH4)2Fe(SO4)2 (mol/L); and V was the volume (mL) of DI water or filtrate.
Isotherm adsorption
The time of equilibrium adsorption was determined before isotherm adsorption. The initial dye concentration was the same as that mentioned above, and the ratio of adsorbent versus dye solution was 0.25 g/25 mL. The adsorption tests were carried out at 30°C from 5 min to 6 h to determine the equilibration time.
Isotherm adsorption experiments were conducted for different initial concentrations (1200, 1500, 1800, and 2100 mg/L for MB, and 500, 750, 1000, and 1250 mg/L for PR). The adsorbent concentration and adsorption temperature were the same as those above, but the adsorption time was 4 h. After adsorption, the experimental results were examined using Langmuir (Eq. (3)) and Freundlich (Eq. (4)) isotherm models:
where Ce is the dye concentration in solution at equilibrium; Qe is the adsorption capacity of the adsorbent at equilibrium; Qm is the maximum capacity of the adsorbent; and KL is the Langmuir adsorption constant (L/mg). The term KF is the Freundlich constant (L/mg), and n is the heterogeneity factor for the Freundlich isotherm model.
Kinetic adsorption
The results of the kinetics study were obtained for different temperatures (30, 45, and 60oC) and adsorption times (10, 20, 40, 60, and 80 min.). The ratio of adsorbent versus dye solution was 0.25 g/ 25 mL, and the initial concentrations of MB and PR were 1200 and 500 mg/L, respectively. The results were analyzed with two adsorption kinetic models, namely, the pseudo-first-order (Eq. (5)) and pseudo-second-order kinetic models (Eq. (6)):
where Qe (mg/g) is the adsorption capacity at equilibrium, and Qt(mg/g) is the adsorption uptake at time t (min.). The terms k1 and k2are the rate constants of the pseudo-first-order and pseudo-second-order models.
Characteristics of paper sludge and PC600
The results of chemical and ignition loss analyses of the paper sludge used in this study are shown in Table 1. The water content was 65%, and the ignition loss of the dry sludge was 54.68%. High values of ignition loss indicated the high organic content of the paper sludge. After ignition loss test, the paper sludge ash was digested with aqua regia and hydrofluoric acid. The element concentration of ash was determined by AAS. The compositions are presented as oxides, and the values are listed in Table 1. The major inorganic element of paper sludge was Ca, which might arise from the neutralizer used in wastewater treatment (i.e. lime or slaked lime) or papermaking filler used in the papermaking process (Ochoa de Alda 2008). Silicon content took second place. The percentage of SiO2 in paper sludge was 16.7 %. Other elements present in the paper sludge such as Mg, Al, Na, and K were not abundant and the percentages of these oxides were all less than 2 %. The result of the XRD analysis (see Fig. 1) matched the chemical analysis and showed that the major component of the sludge was CaCO3.
Table 1. Analysis of Paper Sludge
Fig. 1. XRD analysis of the paper sludge, P600 and PC600. P600 was pyrolyzed paper sludge without acid washing. PC600 was pyrolyzed paper sludge with acid washing.
After pyrolysis, according to the XRD analysis in Fig. 1, CaCO3 was still the principal crystal phase of the P600, since the decomposition temperature of CaCO3 is higher than 700°C (Yang et al. 2008) and the pyrolysis temperature used in this study was below the decomposition temperature of CaCO3. P600 was then washed with 1M HCl and DI water to form PC600. Acid washing was applied for two reasons: one is that paper sludge is an alkaline waste and the pH value of dye solution would have increased during the adsorption experiment. The reason for this was probably the amount of acidic surface functional groups decreasing in the organic fraction and the surface of the sample becoming more alkaline during pyrolysis (Rio et al. 2006). Another possible reason is inorganic salt (such as calcium carbonate in the adsorbent) being removed, leading to an increase in the specific surface area of the adsorbent, which led to improved adsorption ability. After acid washing, the major crystal phase of PC600 changed to SiO2 because of the dissolution of calcium carbonate. Ros et al. (2006) investigated pyrolyzed sewage sludge washed with 5 M HCl. The ash content dropped from 66.1% to 45.5%, and the specific surface area increased from 13 m2/g to 188 m2/g. Chemical analyses revealed that the Fe, Ca, and Mg contents decreased and the weight percent of Si increased. Bagreev et al.(2001) also investigated sewage sludge pyrolysis and reported that the specific surface area increased from 17 m2/g to 41 m2/g after acid washing with 16% HCl. In this study, the loss on ignition of PC600 was 52.27%, which was higher than that of P600 in Table 1. In addition, the CaO and MgO contents decreased from 30.94% to 0.27% and 6.08% to 2.87%, and the content of insoluble ingredients such as SiO2 and Al2O3 increased from 16.35% to 35.33% and 1.56% to 3.7%, respectively. The results corresponded to the XRD analysis, and most of the Ca salts were dissolved by HCl. SEM images also showed the effects of acid washing on calcium salt dissolution.
Figure 2 gives SEM images of P600 and PC600, and reveals that particle size was obviously reduced with acid washing treatment. Corresponding to the results of SEM imaging, specific surface area increased from 13.25 to 193.86 m2/g after acid washing. The adsorption capacities of MB for P600 and PC600 were 29.38 and 115.7 mg/g, respectively and those for PR were 19.15 and 51.6 mg/g, respectively. Adsorption conditions were 30oC for 4 h (the initial concentrations of MB and PR were 1200 mg/L and 500 mg/L, respectively). The results show that acid washing can increase adsorption capacity by increasing specific surface area.
Fig. 2. SEM images of P600 and PC600 (x400): (a) P600 (b) PC600.
PC600 was chosen as dye adsorbent. The specific surface area was 193.86 m2/g, and most of the pore diameter (by volume) was between 2.5 to 5 nm, according to the BJH method (see Fig. 3); this data suggested that PC600 was a mesoporous adsorbent. The pore volume can also be calculated from the amount of N2 adsorbed at different P/P0 condition (Hayashi et al. 2000), where P and P0 were the partial pressure and saturated vapor pressure of N2, respectively. The volume of the micropore was calculated from the amount of adsorption at P/P0 = 0.1. The value corresponding to P/P0 = 0.1 was 0.0714 cm3/g. On the other hand, the volume of the total pore was 0.1870 cm3/g, which was calculated at P/P0 = 0.95. The volume of the mesopore was obtained by subtracting the micropore volume from total pore volume (i.e. 0.1156 cm3/g). The ratio of the volume of the micropores to the total pore volume was 38.18%, whereas the mesopores was 61.82%. These results indicated that the mesopores were a major constituent of PC600.
The zeta potential of the PC600 was also measured to evaluate the surface charge of PC600. The results are shown in Fig. 4. The zeta potential was affected by the pH conditions. The zeta potential value was positive in acidic and negative in alkaline conditions. The isoelectric point of PC600 was around pH 3, which indicated that the zeta potential was 0 at ~pH 3. Zeta potential can afford electrostatic attraction or repulsion of ions, which was important consideration for ionic dye adsorption in this study.
Fig. 3. Pore volume distribution of PC600
Fig. 4. Zeta potential of the PC600 from pH 2 to pH 10
Effect of pH on dye adsorption
Adsorption pH conditions are an important variable for dye adsorption. Cationic dyes tend to be adsorbed at relatively high pH values, whereas anionic dyes are generally adsorbed at low pH (Hubbe et al. 2012). The results of ionic dye adsorption by PC600 are shown in Fig. 5. The adsorption of MB increased but PR decreased with increased pH. The phenomenon can be ascribed to the zeta potential of PC600, which was positively charged at low pH conditions and attracted anion dyes such as PR. By contrast, the cationic dye of MB was adsorbed well at high pH conditions where the zeta potential was negative. Besides, electrostatic attraction was not the only adsorption mechanism due to the adsorption of MB at pH 2.6 and that of PR at pH 7.5. In these situations, PC600 possessed the same charge as ionic dyes, but the adsorption percentage of MB and PR were still higher than 50%. This cannot be explained by electrostatic interaction. The adsorption of organic compounds, aromatic compounds in particular, involves a complex interplay of electrostatic and dispersive interactions (Rivera-Utrilla and Sánchez-Polo 2002). Ayranci and Duman (2006) reported that the cationic state of nicotinic acid and 4-aminobenzoic acid can be adsorbed by activated carbon, for which the surface was definitely positively charged in 0.4M H2SO4 solution. On the other hand, benzoic acid, nicotinic acid, and 4-aminobenzoic acid were monoanonic in 0.1 M NaOH solution and adsorbed in small amounts on activated carbon even though the surface charge of activated carbon was negative. The authors mentioned that the dispersion interactions and either the π-electrons of the aromatic ring or the dipole of adsorbates overcame the electrostatic repulsion, thereby assisting the adsorption process. In our study, MB and PR were also aromatic compounds; thus the adsorptions of MB in acid solution and of PR in alkali solution might also be assisted by dispersion interactions.
Fig. 5. Adsorption of MB and PR at different pH conditions. (MB initial concentration: 1200 mg/L; PR initial concentration: 500 mg/L, adsorption condition: 30 oC, 4 h)
Chemical oxygen demand (COD) was also used to measure the adsorption efficiency of PC600. COD is one of the wastewater effluent parameters monitored and regulated by Taiwan. COD indicates the organic pollution load in water and is defined as the number of oxygen equivalents consumed in the oxidation of organic compounds using strong oxidizing agents, such as K2Cr2O7 (Yang et al. 2011). The results are shown in Fig. 6.
Fig. 6. Chemical oxygen demand (COD) of the filtrate of MB and PR adsorption for different pH conditions
The dashed line shows the effluent standards for Taiwan at 160 mg/L. The COD value of the filtrate correlated with the residual concentration of dye, which was high at a low adsorption percentage. For MB adsorption, the residual concentration in pH 7.5 was 74.6 mg/L and the COD value was 184 mg/L. On the other hand, the residual concentration and the COD value for PR in pH 3.5 were 35.4 mg/L and 136 mg/L, respectively. In other words, the residual concentrations should be lower than 74.6 mg/L for MB and 35.4 mg/L for PR to ensure the values of COD are lower than the regulatory requirement.
Adsorption equilibrium time was measured in the first step, and the adsorption conditions are listed: at pH = 7.5, 1200 mg/L of the MB initial dye concentration and at pH = 3.5, 500 mg/L of the PR initial dye concentration. The ratio of PC600 versus dye solution was 0.25 g/25 mL for both dyes and adsorption temperature was 30°C. The results are shown in Fig. 7. The adsorption percentages increased quickly over the 30 min. for both MB and PR adsorptions. Equilibrium time was considered to be 4 h for PC600.
Fig. 7. Dye adsorption percentage versus time
Isotherm adsorption experiments were conducted for different initial concentra-tions (1200, 1500, 1800, and 2100 mg/L for MB, and 500, 750, 1000, and 1250 mg/L for PR), and the results are listed in Table 2. The results were modeled using Langmuir (Eq. (3)) and Freundlich (Eq. (4)) equations. The coefficients of determination (R2) for the equation fittings and the parameter values for each equation are listed in Table 3. For the Langmuir equation, the values of Qm and KL were from the slope and intercept of the linear plots of Ce/Qe versus Ce, and the values of n and KF were from the slope and intercept of the linear plots of log Qe versus log Ce for the Freundlich equation. The R2 value of Langmuir was higher than that of Freundlich, which means the adsorption behaviors of MB and PR fit the Langmuir better than Freundlich model. The Freundlich adsorption isotherm is a relationship between the amount of adsorption and the concen-tration of the adsorbate in the liquid. This is an empirical equation and may fail to fit the experiment data at high adsorbate concentrations. Maximum adsorption capacity can be calculated from the Langmuir equation. The value for MB was 119.04 mg/g and that for PR was 65.79 mg/g. The values of the adsorption capacity show that PC600 possessed higher adsorption ability toward MB than PR.
Table 2. Isotherm Adsorption Results of PC600
Table 3. Parameters of Adsorption Isotherm Models Fitting for MB and PR
The dimensionless separation factor, RL, was calculated from the fitted Langmuir isotherm equation to determine the type of adsorption process (Tseng, 2007),
where Ci is the initial concentration of the adsorption process and RLis classified as: RL > 1 meaning unfavorable adsorption; 0< RL <1, meaning favorable adsorption; and RL = 0, meaning irreversible adsorption (Tseng, 2007). In this study, the RL value of MB and PR was between 0 to 1 when Ci was between 1200 to 2100 mg/L for MB, and 500 to 1250 mg/L for PR. The RL value indicates that the adsorption types for MB and PR were favorable when PC600 was utilized.
Adsorption kinetics
Adsorption kinetics can be analyzed using of pseudo-first-order and pseudo-second-order kinetic models (Lin et al. 2011). Hubbe et al.(2012) mentioned that the adsorption which fitted pseudo-first-order model might be correlated to certain functional groups on the substrates. On the contrary, the adsorption kinetics fitted with pseudo-second-order model probably represented that the rate-determining step of adsorption involved two functional groups at the substrate surface. Besides, the adsorption rate was depended on the square of the unfilled adsorption sites since the origin form of Eq. 6 was:
The fact that the adsorption behavior corresponds to the pseudo-second-equation should reveal that the last remaining sites become increasingly reluctant to be filled. In this study, the adsorption temperatures were 30, 45, and 60°C, and the adsorption durations were 10, 20, 40, 60, and 80 min. The initial concentrations for MB and PR were 1200 mg/L and 500 mg/L, respectively. As a result, a higher R2 value represents the adsorption kinetics of MB and PR fitting well with the pseudo-second-order kinetic model (see Table 4). The adsorption of ionic dye was not correlated to certain functional groups but was affected by both electrostatic and dispersion interaction. The two interactions might affect the rate-determining step of adsorption, and the correlation coefficient of t/Qt versus t was close to 1 when the pseudo-second-order model was utilized.
The temperature dependence of rate constants can be described by the Arrhenius equation:
where k2, A, Ea, R, and T represent the rate constant, frequency factor, activation energy, gas constant, and absolute temperature of the pseudo-second-order model. The value of activation energy (Ea) can be obtained by the slope of plotting ln k2 against 1/T. The values of Ea for MB and PR adsorption were 12.32 and 2.88 kJ/mol, respectively. Additionally, the magnitude of Ea can provide clues if the adsorption process is chemical or physical process (Han et al.2009). Values of Ea for physical adsorption are usually < 4.2 kJ/mol since the forces involved in physical adsorption are weak. Chemical adsorption involves forces much stronger than in physical adsorption and the values of Ea are typically between 8.4 and 83.7 kJ/mol. Non-activated chemical adsorption has Ea values near zero (Aksu 2002). In this study, according to the Ea values, the adsorption types of PR and MB should be physical and activated chemical adsorption, respectively.
Table 4. Parameters of Adsorption Kinetics Models Fitting for MB and PR
Paper sludge was pyrolyzed at 600°C for 1 h and washed with 1M HCl to form carbonaceous adsorbent (PC600) for MB and PR. PC600 was a found to be mesoporous material having a specific surface area of 193.86 m2/g and a pore diameter distribution of 2.5 to 5 nm. The isoelectric point was located at pH 3, meaning that the particles of PC600 possessed a positive charge at pH < 3 and negative charge at pH > 3. The adsorption results of MB and PR fitted the Langmuir equation well, and the maximum adsorption capacities of MB and PR were 119.04 mg/g and 65.79 mg/g, respectively. The COD value of the filtrate after MB adsorption in pH 10 was 81.6 mg/L, and that of PR in pH 3 was 78 mg/L. These values are lower than the 160 mg/L requirement for effluent standards in Taiwan. The adsorption behavior of both dyes fitted the pseudo-second-order kinetic model, and the respective activation energies calculated from the Arrhenius equation for MB and PR were 12.32 and 2.88 kJ/mol. Accordingly, the adsorption types of MB and PR should be classed as chemical and physical adsorption, respectively.
Aksu, Z. (2002). "Determination of the equilibrium, kinetic and thermodynamic parameters of the batch biosorption of nickel (II) ions onto Chlorella vulgaris," Process Biochem. 38(1), 89-99.
Ayranci, E., and Duman, O. (2006). "Adsorption of aromatic organic acids onto high area activated carbon cloth in relation to wastewater purification," J. Hazard. Mater. 136(3), 542-552.
Bagreev, A., Bandosz, T. J., and Locke, D. C. (2001). "Pore structure and surface chemistry of adsorbents obtained by pyrolysis of sewage sludge-derived fertilizer," Carbon 39(13), 1971-1979.
Barrett, E.P., Joyner, L.G., Halenda, P.P. (1951). "The determination of pore volume and area distributions in porous substances. 1. Computations from nitrogen isotherms," J. Am. Chem. Soc. 73(1), 373-380.
Brunauer, S., Emmett, P.H., Teller, E. (1938). "Adsorption of gases in multimolecular layers," J. Am. Chem. Soc. 60(2), 309-319.
Crini, G. (2006). "Non-conventional low-cost adsorbents for dye removal: A review," Bioresource Technol. 97(9), 1061-1085.
Doğan, D., and Türkdemir, H. (2005). "Electrochemical oxidation of textile dye indigo," J. Chem. Technol. Biotechnol. 80(8), 916-923.
Demiral, H., Demiral, I., Karabacakoğlu, B., and Tümsek, F. (2011). "Production of activated carbon from olive bagasse by physical activation," Chem. Eng. Res. Des. 89(2), 206-213.
Gupta, V. K., and Suhas. (2009). "Application of low-cost adsorbents for dye removal – A review," J. Environ. Manage. 90(8), 2313-2342.
Han, R., Zhang, J., Han, P., Wang, Y., Zhao, Z., and Tang, M. (2009). "Study of equilibrium, kinetic and thermodynamic parameters about methylene blue adsorption onto natural zeolite," Chem. Eng. J. 145(3), 496-504.
Hayashi, J., Kazehaya, A., Muroyama, K., and Watkinson, A. P. (2000). "Preparation of activated carbon from lignin by chemical activation," Carbon 38(13), 1873-1878.
Hubbe, M. A., Beck, K. R., O'Neal, W. G., Sharma, Y. Ch. (2012). "Cellulosic substrates for removal of pollutants from aqueous systems: A review. 2. Dyes," BioResources 7(2), 2592-2687.
Jain, A. K., Gupta, V. K., Bhatnagar, A., and Suhas. (2003). "Utilization of industrial waste products as adsorbents for the removal of dyes," Journal of Hazardous Materials B101, 31-42.
Jia, Q., and Lua, A. C. (2008). "Effects of pyrolysis conditions on the physical characteristics of oil-palm-shell activated carbons used in aqueous phase phenol adsorption," J. Anal. Appl. Pyrol. 83(2), 175-179.
Khezami, L., Ould-Dris, A., and Capart, R. (2007). "Activated carbon from thermo-compressed wood and other lignocellulosic precursors,"BioResources 2(2), 193-209.
Kim, T. H., Park, C., and Kim, S. (2005). "Water recycling from desalination and purification process of reactive dye manufacturing industry by combined membrane filtration," J. Clean. Prod. 13(8), 779-786.
Lin, Y. F., Chen, H. W., Chien, P. S., Chiou, C. S., and Liu, C. C. (2011). "Application of bifunctional magnetic adsorbent to adsorb metal cations and anionic dyes in aqueous solution," J. Hazard. Mater. 185(2-3), 1124-1130.
Liu, Z., Zhou, A., Wang, G., and Zhao, X. (2009). "Adsorption behavior of methyl orange onto modified ultrafine coal powder," Chinese J. Chem. Eng. 17(6), 942-948.
Lucas, M. S., and Peres, J. A. (2006). "Decolorization of the azo dye Reactive Black 5 by Fenton and photo-Fenton oxidation," Dyes Pigments. 71(3), 236-244.
Martin, M. J., Artola, A., Balaguer, M. D., and Rigola, M. (2002). "Towards waste minimization in WWTP: Activated carbon from biological sludge and its application in liquid phase adsorption," J. Chem. Technol. Biot. 77(7), 825-833
Maschio, S., Furlani, E., Tonello, G., Faraone, N., Aneggi, E., Minichelli, D., Fedrizzi, L., Bachiorrini, A., and Bruckner, S. (2009). "Fast firing of tiles containing paper mill sludge, glass cullet and clay," Waste Manage. 29(11), 2880-2885.
Miguel, G. S., Fowler, G. D., and Sollars, C. J. (2003). "A study of the characteristics of activated carbons produced by steam and carbon dioxide activation of waste tyre rubber," Carbon 41(5), 1009-1016.
Mohan, D., Singh, K. P., Singh, G., and Kumar, K. (2002). "Removal of dyes from wastewater using flyash, a low-cost adsorbent," Ind. Eng. Chem. Res. 41(15), 3688-3695.
Monsalvo, V. M., Mohedano, A. F., and Rodriguez, J. J. (2011). "Activated carbons from sewage sludge. Application to aqueous-phase adsorption of 4-chlorophenol," Desalination 277(1-3), 377-382.
Nakagawa, K., Namba, A., Mukai, S. R., Tamon, H., Ariyadejwanich, P., and Tanthapanichakoon, W. (2004). "Adsorption of phenol and reactive dye from aqueous solution on activated carbons derived from solid wastes," Water Res. 38(7), 1791-1798.
Ochoa de Alda, J. A. G. (2008). "Feasibility of recycling pulp and paper mill sludge in the paper and board industries," Resources, Conservation and Recycling 52(7), 965-972.
Olivella, M. À., Fiol, N., Torre, F. D. L., Poch, J., and Villaescusa I. (2012). "A mechanistic approach to methylene blue sorption on two vegetable wastes: Cork bark and grape stalks," BioResources. 7(3), 3340-3354.
Purnomo, C. W., Salim, C., and Hinode, H. (2012). "Effect of the activation method on the properties and adsorption behavior of bagasse fly ash-based activated carbon," Fuel Process. Technol. 102(October 2012), 132-139.
Rafatullah, M., Sulaiman, O., Hashim, R., Ahmad, A. (2010) "Adsorption of methylene blue on low-cost adsorbents: A review," Journal of Hazardous Materials, 177, 70-80.
Rio, S., Le Coq, L., Faur, C., Lecomte, D., and Le Cloirec, P. (2006) "Preparation of adsorbents from sewage sludge by steam activation for industrial emission treatment," Process Safty and Environmental Protection, 84(B4), 258-264.
Rivera-Utrilla, J., and Sánchez-Polo, M. (2002). "The role of dispersive and electrostatic interactions in the aqueous phase adsorption of naphthalenesulphonic acids on ozone-treated activated carbons," Carbon, 40(14), 2685-2691.
Rodriguez-Reinoso, F., Lopez-Gonzalez, J. de D., and Berenguer, C. (1982). "Activated carbons from almond shells-1: Preparation and characterization by nitrogen adsorption," Carbon 20(6), 513-518.
Ros, A., Lillo-Ródenas, M. A., Fuente, E., Montes-Morán, M. A., Martin, M. J., and Linares-Solano, A. (2006). "High surface area materials prepared from sewage sludge-based precursors," Chemosphere. 65(1), 132-140.
Sahu, J. N., Acharya, J., and Meikap, B. C. (2010). "Optimization of production conditions for activated carbons from Tamarind wood by zinc chloride using response surface methodology," Bioresource Technol. 101(6), 1974-1982.
Shi, B. Y., Li, G. H., Wang, D. S., Feng, C. H., and Tang, H. X. (2007a). "Removal of direct dyes by coagulation: The performance of preformed polymeric aluminum species," J. Hazard. Mater. 143(1-2), 567-574.
Shi, B. Y., Li, G., Wang, D., and Tang, H. (2007b). "Separation of Al13 from polyaluminum chloride bisulfate precipitation and nitrate metathesis," Sep. Purif. Technol. 54(1), 88-95.
Sun, Q., and Yang, L. (2003). "The adsorption of basic dyes from aqueous solution on modified peat-resin particle," Water Res. 37(7), 1535-1544.
Tseng, R. L. (2007). "Physical and chemical properties and adsorption type of activated carbon prepared from plum kernels by NaOH activation," J. Hazard. Mater. 147(3), 1020-1027.
Walker, G. M., and Weatherley, L. R. (1998). "Fixed bed adsorption of acid dyes onto activated carbon," Environ. Pollut. 99(1), 133-136.
Waranusantigul, P., Pokethitiyook, P., Kruatrachue, M., and Upatham, E. S. (2003). "Kinetics of basic dye (methylene blue) biosorption by giant duckweed (Spirodela polyrrhiza)," Environ. Pollut. 125(3), 385-392.
Yang, D. H., Hur, B. Y., and Yang, S. R. (2008). "Study on fabrication and foaming mechanism of Mg foam using CaCO3 as blowing agent," J. Alloy Compd. 461(1-2), 221-227.
Yang, J., Chen, J., Zhou, Y., and Wu, K. (2011). "A nano-copper electrochemical sensor for sensitive detection of chemical oxygen demand," Sensor Actuat. B: Chem. 153(1), 78-82.
Article submitted: October 20, 2012; Peer review completed: December 8, 2012; Revised version received and accepted: January 7, 2013; Published: January 9, 2013.


text:
Q: Recursive printing issue in C++ I am running into what I believe is a recursive issue which I do not know how to resolve. I am designing a hashed array tree structure and I want to print out the "lowest level" in the hashed array tree. I have an array which keeps track of how many nodes are on each level, and I can calculate the lowest level based on this. Here is the code:
template <typename T>
ostream &operator << ( ostream &output, const HashNode<T> &node ){
if(node.stemNode == 0){
  //leafnode

  for(int i=0; i < node.numElements; i++){

    output << "\n-------------------------------------------" << endl;
    output << "This Node's Level: " << node.nodeLevel << endl;
    output << "\nKey: " << node.keyArray[i] << endl;
    output << "\nData: " << *(node.dataArray[i])  << endl;
  }

}else if (node.stemNode == 1) {
  //stem node

  for(int j=0; j<5; j++){
    if(node.childArray[j] != NULL){
      output << *(node.childArray[j]);
    }
  }

}
int ctr = 0;
for(int i=8; i>=0; i--){
  if(levels[i] == 0){
    ctr++;
  }
}
int lowest = 9-(ctr+1);
//output << "\nLowest Number of Levels: " << 9-(ctr+1) << endl;

return output << "\n\nLowest Level: " << lowest << " " << ctr2 << endl;
}

What happens is that when I print out output, the phrase "Lowest Level" will print out multiple times. I believe this occurs because I traverse my tree recursively. I tried to overcome this by just saving the "lowest level" value to a variable as shown above, but this did not solve the problem. The line continues to print multiple times. Is there a way to overcome this?

A: You always send the "Lowest level" string to output, regardless of whether it's a stemnode or not. Move the "Lowest level" line to inside if(stemnode == 0) and just return output by default.
A rough rule of recursion; if you only have one return statement you probably have issues with your end conditions.

A: From the comments I know that the goal is to have the "Lowest Level" part printed once. This can be done with small modifications of your original code. Change your original printing function to this function head:
template <typename T>
ostream &printHashNode(ostream &output, const HashNode<T> &node){
    //your old code leaving out the "Lowest Level" part

and remove the "Lowest Level" part.
Then make a new function for printing:
template <typename T>
ostream &operator << (ostream &output, const HashNode<T> &node){
    return output << printHashNode(output, node) << "\n\nLowest Level: " << lowest << " " << ctr2 << endl;
}

If you require the value ctr2 calculated by printHashNode you can also pass that back from it.

redpajama_set_name: RedPajamaStackExchange